Forgot to mention, I use MySQL 5.1.
On May 23, 4:29 pm, Fay <[EMAIL PROTECTED]> wrote: > Hi, > > I encountered a situation that foreign key constraints were generated > differently for the same data model. > > Below is my test model that has 2 identical sets of 1-to-many tables. > When I run django sqlall command, however the foreign key constraints > were built differently, one used column constraint while the other > used table constraint. It seems the table names contribute to this > behavior. Although they function very similarly, I wonder why that > happened. > > from django.db import models > > class a1(models.Model): > a1c1 = models.CharField(maxlength=200) > > class a2(models.Model): > a2c1 = models.ForeignKey(a1) > a2c2 = models.CharField(maxlength=200, core=True) > > class x1(models.Model): > x1c1 = models.CharField(maxlength=200) > > class x2(models.Model): > x2c1 = models.ForeignKey(x1) > x2c2 = models.CharField(maxlength=200, core=True) > > Results from sqlall command: > > BEGIN; > CREATE TABLE `test_a1` ( > `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, > `a1c1` varchar(200) NOT NULL > ); > CREATE TABLE `test_x2` ( > `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, > `x2c1_id` integer NOT NULL, > `x2c2` varchar(200) NOT NULL > ); > CREATE TABLE `test_x1` ( > `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, > `x1c1` varchar(200) NOT NULL > ); > ALTER TABLE `test_x2` ADD CONSTRAINT x2c1_id_refs_id_11de27b2 FOREIGN > KEY (`x2c1_id`) REFERENCES `test_x1` (`id`); > CREATE TABLE `test_a2` ( > `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, > `a2c1_id` integer NOT NULL REFERENCES `test_a1` (`id`), > `a2c2` varchar(200) NOT NULL > ); > CREATE INDEX `test_x2_x2c1_id` ON `test_x2` (`x2c1_id`); > CREATE INDEX `test_a2_a2c1_id` ON `test_a2` (`a2c1_id`); > COMMIT; > > Thanks. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---