Changes between Initial Version and Version 1 of Ticket #23279


Ignore:
Timestamp:
Aug 16, 2014, 10:04:00 AM (10 years ago)
Author:
Baptiste Mispelon
Comment:

Hi,

Indeed, there seem to be a difference between the two (it looks like an ordering issue where the tables are created in an order that prevents sqlite from referencing the model tables from the m2m one).

However, this issue is gone if you use the new migrations framework in 1.7 so I'm tempted to mark this ticket as wontfix.

What do you think?

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #23279 – Description

    initial v1  
    11If I have the following class definition:
    2 
     2{{{#!python
    33class Foo(models.Model):
    44    bars = models.ManyToManyField('Bar')
     
    99    class Meta:
    1010        db_table = 'bar'
    11 
     11}}}
    1212Then, syncdb will create in SQLite3 the following intermediate table. Note that there is no REFERENCES constrains defined.
    1313
     14{{{#!sql
    1415CREATE TABLE "foo_bars" (
    1516    "id" integer NOT NULL PRIMARY KEY,
     
    2021CREATE INDEX "foo_bars_e69b476d" ON "foo_bars" ("bar_id");
    2122CREATE INDEX "foo_bars_ef315d12" ON "foo_bars" ("foo_id")
     23}}}
    2224
    2325If I define ManyToManyField in Bar class as opposed to Foo class, such as
    2426
     27{{{#!python
    2528class Foo(models.Model):
    2629    class Meta:
     
    3134    class Meta:
    3235        db_table = 'bar'
     36}}}
    3337
    3438Then, the intermediate table becomes:
    3539
     40{{{#!sql
    3641CREATE TABLE "bar_foos" (
    3742    "id" integer NOT NULL PRIMARY KEY,
     
    4247CREATE INDEX "bar_foos_e69b476d" ON "foo_bars" ("bar_id");
    4348CREATE INDEX "bar_foos_ef315d12" ON "foo_bars" ("foo_id")
     49}}}
    4450
    4551Now only foo_id has REFERENCES constraint.
     
    4753If I choose MySQL instead of SQLite3, syncdb creates REFERENCE constrains for both foo_id and bar_id, as follows:
    4854
     55{{{#!sql
    4956CREATE TABLE `bar_foos` (
    5057  `id` int(11) NOT NULL AUTO_INCREMENT,
     
    5865  CONSTRAINT `foo_id_refs_id_27f38014` FOREIGN KEY (`foo_id`) REFERENCES `foo` (`id`)
    5966) ENGINE=InnoDB
     67}}}
    6068
    6169So, there seems an issue when syncdb creates an intermediate table derived from ManyToManyField for SQLite3.
Back to Top