#24311: Foreign key constraint error when syncing unmigrated models that relate 
to
migrated models
---------------------------------+--------------------------------------
     Reporter:  collinanderson   |                    Owner:  nobody
         Type:  Bug              |                   Status:  closed
    Component:  Migrations       |                  Version:  1.8alpha1
     Severity:  Release blocker  |               Resolution:  wontfix
     Keywords:                   |             Triage Stage:  Unreviewed
    Has patch:  0                |      Needs documentation:  0
  Needs tests:  0                |  Patch needs improvement:  0
Easy pickings:  0                |                    UI/UX:  0
---------------------------------+--------------------------------------
Changes (by MarkusH):

 * status:  new => closed
 * resolution:   => wontfix


Comment:

 On 1.8 this is the SQL run by the syncdb code (last query fails):

 {{{#!sql
 CREATE TABLE `app_myuser` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY
 KEY, `password` varchar(128) NOT NULL, `last_login` datetime(6) NULL,
 `is_superuser` bool NOT NULL, `username` varchar(30) NOT NULL UNIQUE,
 `first_name` varchar(30) NOT NULL, `last_name` varchar(30) NOT NULL,
 `email` varchar(254) NOT NULL, `is_staff` bool NOT NULL, `is_active` bool
 NOT NULL, `date_joined` datetime(6) NOT NULL) None
 SELECT engine FROM information_schema.tables WHERE table_name = %s
 ['app_myuser']
 CREATE TABLE `app_myuser_groups` (`id` integer AUTO_INCREMENT NOT NULL
 PRIMARY KEY, `myuser_id` integer NOT NULL, `group_id` integer NOT NULL,
 UNIQUE (`myuser_id`, `group_id`)) None
 SELECT engine FROM information_schema.tables WHERE table_name = %s
 ['app_myuser_groups']
 CREATE TABLE `app_myuser_user_permissions` (`id` integer AUTO_INCREMENT
 NOT NULL PRIMARY KEY, `myuser_id` integer NOT NULL, `permission_id`
 integer NOT NULL, UNIQUE (`myuser_id`, `permission_id`)) None
 SELECT engine FROM information_schema.tables WHERE table_name = %s
 ['app_myuser_user_permissions']
     Running deferred SQL...
 ALTER TABLE `app_myuser_groups` ADD CONSTRAINT
 `app_myuser_groups_myuser_id_2b41e8461df0328_fk_app_myuser_id` FOREIGN KEY
 (`myuser_id`) REFERENCES `app_myuser` (`id`) None
 ALTER TABLE `app_myuser_groups` ADD CONSTRAINT
 `app_myuser_groups_group_id_7a5f5bcafc6997d9_fk_auth_group_id` FOREIGN KEY
 (`group_id`) REFERENCES `au
 }}}

 On 1.7 the respective SQL is the following (no failures):

 {{{#!sql
 CREATE TABLE `app_myuser_groups` (`id` integer AUTO_INCREMENT NOT NULL
 PRIMARY KEY, `myuser_id` integer NOT NULL, `group_id` integer NOT NULL,
 UNIQUE (`myuser_id`, `group_id`)); None
 CREATE TABLE `app_myuser_user_permissions` (`id` integer AUTO_INCREMENT
 NOT NULL PRIMARY KEY, `myuser_id` integer NOT NULL, `permission_id`
 integer NOT NULL, UNIQUE (`myuser_id`, `permission_id`)); None
 CREATE TABLE `app_myuser` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY
 KEY, `password` varchar(128) NOT NULL, `last_login` datetime NOT NULL,
 `is_superuser` bool NOT NULL, `username` varchar(30) NOT NULL UNIQUE,
 `first_name` varchar(30) NOT NULL, `last_name` varchar(30) NOT NULL,
 `email` varchar(75) NOT NULL, `is_staff` bool NOT NULL, `is_active` bool
 NOT NULL, `date_joined` datetime NOT NULL); None
 ALTER TABLE `app_myuser_groups` ADD CONSTRAINT
 `myuser_id_refs_id_08272aba` FOREIGN KEY (`myuser_id`) REFERENCES
 `app_myuser` (`id`); None
 ALTER TABLE `app_myuser_user_permissions` ADD CONSTRAINT
 `myuser_id_refs_id_becb7d62` FOREIGN KEY (`myuser_id`) REFERENCES
 `app_myuser` (`id`); None
 CREATE INDEX `app_myuser_groups_f1d9e869` ON `app_myuser_groups`
 (`myuser_id`); None
 CREATE INDEX `app_myuser_groups_5f412f9a` ON `app_myuser_groups`
 (`group_id`); None
 CREATE INDEX `app_myuser_user_permissions_f1d9e869` ON
 `app_myuser_user_permissions` (`myuser_id`); None
 CREATE INDEX `app_myuser_user_permissions_83d7f98b` ON
 `app_myuser_user_permissions` (`permission_id`); None
 }}}

 However, looking at the constraints for `app_myuser_groups` this reveals a
 missing constraint to `auth_group`.

 {{{#!sql
 CREATE TABLE `app_myuser_groups` (
   `id` int(11) NOT NULL AUTO_INCREMENT,
   `myuser_id` int(11) NOT NULL,
   `group_id` int(11) NOT NULL,
   PRIMARY KEY (`id`),
   UNIQUE KEY `myuser_id` (`myuser_id`,`group_id`),
   KEY `app_myuser_groups_f1d9e869` (`myuser_id`),
   KEY `app_myuser_groups_5f412f9a` (`group_id`),
   CONSTRAINT `myuser_id_refs_id_08272aba` FOREIGN KEY (`myuser_id`)
 REFERENCES `app_myuser` (`id`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8
 }}}

 In other words, 1.7 seems to silently ignore to add constraints to missing
 tables.

 See the docs as well:
 https://docs.djangoproject.com/en/1.7/topics/migrations/#unmigrated-
 dependencies

--
Ticket URL: <https://code.djangoproject.com/ticket/24311#comment:4>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/072.7c3905bd18c1c16d6cdff9c953398a45%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to