Reputation: 18264
I changed one of my models to go from
serial_number = models.BigIntegerField(unique=True)
to
serial_number = models.AutoField(primary_key=True)
and ran
$ python manage.py check -v 3
$ python manage.py makemigrations -v 2
$ python manage.py migrate -v 2
However, when I try to run the unit tests (which passed fine before), I get this error:
[...]
File "/home/usr/Envs/intranet/lib/python2.7/site-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
raise errorclass, errorvalue django.db.utils.OperationalError: (1075, 'Incorrect table definition; there can be only one auto column and it must be defined as a key')
How to resolve this?
Upvotes: 0
Views: 319
Reputation: 11
The Error1075 'Incorrect table definition' came from Mysql, not Django. That is because the table u changed got 2 auto_created fields, while it is only one field alled allow for one table in Mysql.
In Django, just add a parm 'auto_created':
serial_number = models.AutoField(primary_key=True, auto_created=False)
then remove u old migrations file last time and make migrations again, continue migrate will be ok.
Upvotes: 1
Reputation: 18264
So far the only "solution" was to trash all the migrations and re-create the database. Thus trashing all the old data. But it is less of a pain than fixing this craziness.
Upvotes: 0