Changes between Initial Version and Version 1 of Ticket #23279
- Timestamp:
- Aug 16, 2014, 10:04:00 AM (10 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #23279 – Description
initial v1 1 1 If I have the following class definition: 2 2 {{{#!python 3 3 class Foo(models.Model): 4 4 bars = models.ManyToManyField('Bar') … … 9 9 class Meta: 10 10 db_table = 'bar' 11 11 }}} 12 12 Then, syncdb will create in SQLite3 the following intermediate table. Note that there is no REFERENCES constrains defined. 13 13 14 {{{#!sql 14 15 CREATE TABLE "foo_bars" ( 15 16 "id" integer NOT NULL PRIMARY KEY, … … 20 21 CREATE INDEX "foo_bars_e69b476d" ON "foo_bars" ("bar_id"); 21 22 CREATE INDEX "foo_bars_ef315d12" ON "foo_bars" ("foo_id") 23 }}} 22 24 23 25 If I define ManyToManyField in Bar class as opposed to Foo class, such as 24 26 27 {{{#!python 25 28 class Foo(models.Model): 26 29 class Meta: … … 31 34 class Meta: 32 35 db_table = 'bar' 36 }}} 33 37 34 38 Then, the intermediate table becomes: 35 39 40 {{{#!sql 36 41 CREATE TABLE "bar_foos" ( 37 42 "id" integer NOT NULL PRIMARY KEY, … … 42 47 CREATE INDEX "bar_foos_e69b476d" ON "foo_bars" ("bar_id"); 43 48 CREATE INDEX "bar_foos_ef315d12" ON "foo_bars" ("foo_id") 49 }}} 44 50 45 51 Now only foo_id has REFERENCES constraint. … … 47 53 If I choose MySQL instead of SQLite3, syncdb creates REFERENCE constrains for both foo_id and bar_id, as follows: 48 54 55 {{{#!sql 49 56 CREATE TABLE `bar_foos` ( 50 57 `id` int(11) NOT NULL AUTO_INCREMENT, … … 58 65 CONSTRAINT `foo_id_refs_id_27f38014` FOREIGN KEY (`foo_id`) REFERENCES `foo` (`id`) 59 66 ) ENGINE=InnoDB 67 }}} 60 68 61 69 So, there seems an issue when syncdb creates an intermediate table derived from ManyToManyField for SQLite3.