Changes between Initial Version and Version 1 of Ticket #26777


Ignore:
Timestamp:
Jun 18, 2016, 9:52:04 AM (9 years ago)
Author:
Simon Charette
Comment:

I just tried reproducing against Django 1.9.7 with no success.

Please re-open the ticket by answering these two questions:

  1. Are both of your tables using the InnoDB engine? Foreign keys are not supported on MyISAM.
  2. Are you using a custom user model which you didn't provide the definition?

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #26777

    • Property Resolutionneedsinfo
    • Property Status newclosed
    • Property Type UncategorizedBug
  • Ticket #26777 – Description

    initial v1  
    11I have a model that looks like
    22
     3{{{#!python
     4class LiveEvent(models.Model):
     5    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
     6    ...
     7    attendees = models.ManyToManyField(
     8        User, blank=True, related_name="events_attended"
     9    )
     10    ...
     11    notify_subscriptions = models.ManyToManyField(
     12        User, blank=True, related_name="events_subscribed"
     13    )
     14}}}
     15
     16when trying to add and migrate notify_subscriptions field I get the following error:
     17{{{
     18django.db.utils.IntegrityError: (1215, 'Cannot add foreign key constraint')`
     19}}}
     20
     21When adding
     22
     23{{{#!python
     24'OPTIONS': {
     25    "init_command": "SET foreign_key_checks = 0;",
     26},
     27}}}
     28
     29to database settings , the error became:
    330
    431{{{
    5 class LiveEvent(models.Model):
    6     id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
    7 
    8     ...
    9 
    10     attendees = models.ManyToManyField(User, blank=True, related_name="events_attended")
    11 
    12     ...
    13 
    14     notify_subscriptions = models.ManyToManyField(User, blank=True, related_name="events_subscribed")
    15 
     32django.db.utils.OperationalError: (1825, "Failed to add the foreign key constraint on table 'levan_liveevent_notify_subscriptions'. Incorrect options in FOREIGN KEY constraint 'slipmat/levan_liveevent_noti_liveevent_id_a4871abc_fk_levan_liveevent_id'")
    1633}}}
    17 
    18 when trying to add and migrate notify_subscriptions field I get an `django.db.utils.IntegrityError: (1215, 'Cannot add foreign key constraint')` error. When adding
    19 
    20 {{{
    21 
    22 'OPTIONS': {
    23             "init_command": "SET foreign_key_checks = 0;",
    24         },
    25 }}}
    26 
    27  to database settings , the error becames: `django.db.utils.OperationalError: (1825, "Failed to add the foreign key constraint on table 'levan_liveevent_notify_subscriptions'. Incorrect options in FOREIGN KEY constraint 'slipmat/levan_liveevent_noti_liveevent_id_a4871abc_fk_levan_liveevent_id'")`
    2834
    2935the migration file looks like:
    3036
    31 {{{
    32 
    33     operations = [
    34         migrations.AddField(
    35             model_name='liveevent',
    36             name='notify_subscriptions',
    37             field=models.ManyToManyField(blank=True, related_name='events_subscribed', to=settings.AUTH_USER_MODEL),
     37{{{#!python
     38operations = [
     39    migrations.AddField(
     40        model_name='liveevent',
     41        name='notify_subscriptions',
     42        field=models.ManyToManyField(
     43            blank=True, related_name='events_subscribed', to=settings.AUTH_USER_MODEL
    3844        ),
    39     ]
    40 
     45    ),
     46]
    4147}}}
    4248
Back to Top