#26777: Cannot add foreign key constraint when migrating manytomany field
-------------------------------+--------------------
     Reporter:  Uninen         |      Owner:  nobody
         Type:  Uncategorized  |     Status:  new
    Component:  Migrations     |    Version:  1.9
     Severity:  Normal         |   Keywords:
 Triage Stage:  Unreviewed     |  Has patch:  0
Easy pickings:  0              |      UI/UX:  0
-------------------------------+--------------------
 I have a model that looks like


 {{{
 class LiveEvent(models.Model):
     id = models.UUIDField(primary_key=True, default=uuid.uuid4,
 editable=False)

     ...

     attendees = models.ManyToManyField(User, blank=True,
 related_name="events_attended")

     ...

     notify_subscriptions = models.ManyToManyField(User, blank=True,
 related_name="events_subscribed")

 }}}

 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

 {{{

 'OPTIONS': {
             "init_command": "SET foreign_key_checks = 0;",
         },
 }}}

  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'")`

 the migration file looks like:

 {{{

     operations = [
         migrations.AddField(
             model_name='liveevent',
             name='notify_subscriptions',
             field=models.ManyToManyField(blank=True,
 related_name='events_subscribed', to=settings.AUTH_USER_MODEL),
         ),
     ]

 }}}

 I'm using MySQL version 5.6.27 and Django version 1.9.7

--
Ticket URL: <https://code.djangoproject.com/ticket/26777>
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/049.8ed6d62d3e7beb38dc5f26fbfd97eb95%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to