2007年09月25日 星期二 09:35
Hi£¬´ó¼ÒºÃ¡£ÔÚʹÓÃDjangoµÄʱºòÓöµ½ÁËÒ»¸öÀ§»óµÄµØ·½¡£ ÎÒʹÓÃMysql£¬ÓÐÁ½¸öÄ£ÐͶ¨ÒåÈçÏ£º class Categlog(Model): ................ blog = models.ForeignKey(Blog) .................. class Entry(Model): ................ blog = models.ForeignKey(Blog) .................. ÀíÂÛÉÏÀ´½²£¬Á½¸öÄ£ÐÍÉú³ÉµÄÊý¾Ý¿â¶¼Ó¦¸ÃÓÐÒ»¸öBlog_idµÄÍâ¼ü£¬²¢Óëblog±í²úÉú²ÎÕÕ¹Øϵ¡£ ¿ÉÊÇÔڲ鿴Êý¾Ý¿âµÄÍâ¼ü¹Øϵʱ£¬·¢ÏÖÊý¾Ý¿â±íÀïÃæµÄCatelogÓÐÒ»¸öµ½blog±íµÄÍâ¼ü£¬µ«Entry±íȴûÓС£ ÎÒʹÓÃsql ÃüÁî²é¿´ÁËÒ»ÏÂÉú³ÉµÄÊý¾Ý¿â½Å±¾£º CREATE TABLE `blog_catelog` ( `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, ..................................... `blog_id` integer NOT NULL ...................................... ); ALTER TABLE `blog_catelog` ADD CONSTRAINT blog_id_refs_id_4688511d FOREIGN KEY ( `blog_id`) REFERENCES `blog_blog` (`id`); CREATE TABLE `blog_entry` ( `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, ................................. `blog_id` integer NOT NULL REFERENCES `blog_blog` (`id`), ................................. ); ͨ¹ýÉÏÃæµÄ½Å±¾¿´µ½£¬catelogµÄ±íÉú³ÉÁËÒ»¸öForeign key¡£¶øentry±íûÓУ¬½ö½öÊÇReferencesÁËÒ»ÏÂblogµÄ±í¡£ ÎÒÏ룬²ÎÕÕ²¢²»µÈÓÚÍâ¼ü°É£¬³öÏÖÕâÖÖÇé¿öµÄÔÒòÊÇʲôÄØ£¿¸÷λÅóÓÑÓÐûÓöµ½¹ýÕâÑùµÄÎÊÌ⣿ÈçºÎ½â¾öÄØ£¿Ð»Ð»£¡ -- site:http://www.fallever.com -------------- 下一部分 -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: http://python.cn/pipermail/python-chinese/attachments/20070925/4920bc4a/attachment.html
Zeuux © 2025
京ICP备05028076号