Django MySQL error when creating tables

后端 未结 11 1569
感动是毒
感动是毒 2020-12-14 01:02

I am building a django app with a MySQL DB. When I run \'python manage.py migrate\' for the first time, some tables are created well then some errors appear. The error broug

11条回答
  •  南笙
    南笙 (楼主)
    2020-12-14 01:34

    Make sure both foreign key and primary key are of the same type.

    Foreign key has to be the same type as the primary key of the foreign table. I had a bigint in the foreign table and django did not know how to create a foreign key that was a bigint automatically.

    Investigated why the migration was failing by running: python manage.py sqlmigrate {app_name} {migration_name}

    Run this in the workbench and you will see the real error behind the failure.

    django.db.utils.IntegrityError: (1215, 'Cannot add foreign key constraint')

提交回复
热议问题