#30152: MySQL: Cannot change column 'id': used in a foreign key constraint
-------------------------------+--------------------------------------
     Reporter:  Carsten Fuchs  |                    Owner:  nobody
         Type:  Bug            |                   Status:  closed
    Component:  Migrations     |                  Version:  2.2
     Severity:  Normal         |               Resolution:  needsinfo
     Keywords:  mysql          |             Triage Stage:  Unreviewed
    Has patch:  0              |      Needs documentation:  0
  Needs tests:  0              |  Patch needs improvement:  0
Easy pickings:  0              |                    UI/UX:  0
-------------------------------+--------------------------------------

Comment (by Carsten Fuchs):

 Hi Tim,
 many thanks for your work!

 I've been able to come up with a small example with which I can reproduce
 this.
 Please see the three attached files `models.py` and the migrations
 `0001_initial.py` and `0002_auto_20190201_2242.py`.

 {{{
 #!sh
 (TestDjango22a) carsten@black-steel-ubuntu:~/ticket30152$ ./manage.py
 --version
 2.2a1

 (TestDjango22a) carsten@black-steel-ubuntu:~/ticket30152$ ./manage.py
 startapp Lori

 # settings.py edited

 (TestDjango22a) carsten@black-steel-ubuntu:~/ticket30152$ ./manage.py
 makemigrations
 Migrations for 'Lori':
   Lori/migrations/0001_initial.py
     - Create model Kostenstelle
     - Create model KalenderEintrag

 # changed `id` field definition

 (TestDjango22a) carsten@black-steel-ubuntu:~/ticket30152$ ./manage.py
 makemigrations
 Migrations for 'Lori':
   Lori/migrations/0002_auto_20190201_2242.py
     - Alter field id on kostenstelle

 (TestDjango22a) carsten@black-steel-ubuntu:~/ticket30152$ ./manage.py
 migrate
 Operations to perform:
   Apply all migrations: Lori, admin, auth, contenttypes, sessions
 Running migrations:
   Applying Lori.0001_initial… OK
   Applying Lori.0002_auto_20190201_2242…Traceback (most recent call last):
   File "/home/carsten/.virtualenvs/TestDjango22a/lib/python3.6/site-
 packages/django/db/backends/utils.py", line 84, in _execute
     return self.cursor.execute(sql, params)
   File "/home/carsten/.virtualenvs/TestDjango22a/lib/python3.6/site-
 packages/django/db/backends/mysql/base.py", line 71, in execute
     return self.cursor.execute(query, args)
   File "/home/carsten/.virtualenvs/TestDjango22a/lib/python3.6/site-
 packages/MySQLdb/cursors.py", line 198, in execute
     res = self._query(query)
   File "/home/carsten/.virtualenvs/TestDjango22a/lib/python3.6/site-
 packages/MySQLdb/cursors.py", line 304, in _query
     db.query(q)
   File "/home/carsten/.virtualenvs/TestDjango22a/lib/python3.6/site-
 packages/MySQLdb/connections.py", line 217, in query
     _mysql.connection.query(self, query)
 MySQLdb._exceptions.OperationalError: (1833, "Cannot change column 'id':
 used in a foreign key constraint
 'Lori_kalendereintrag_kostenstelle_id_bcd99894_fk_kostenste' of table
 'LoriDB.Lori_kalendereintrag_kst'")

 The above exception was the direct cause of the following exception:
 # ...
 }}}

 Can you please have a look if you can reproduce it with these files?

-- 
Ticket URL: <https://code.djangoproject.com/ticket/30152#comment:3>
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/066.bedbdd9537aad73c801db0bf57e8f249%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to