Django 1.8, syncdb not working, throwing a foreign key constraint error

断了今生、忘了曾经 提交于 2019-12-24 02:56:24

问题


Since I upgrade to Django 1.8 from 1.7, I have got this foreign key constraint error.

File "c:project\env\lib\site-packages\mysql_python-1.2.5-py2.7-win32.egg/MySQLdb\connections.py line 36, in defaulterrorhandler raise errorclass, errorvalue, 

Django.db.utils.IntergrityError: 'Cannot add foreing key contraint

What's some wrong with django 1.8 (latest version)?


回答1:


Try this

DATABASES = {
'default': {
    ...         
    'OPTIONS': {
         "init_command": "SET foreign_key_checks = 0;",
    },
    'STORAGE_ENGINE': 'MyISAM / INNODB / ETC'
 }
}



回答2:


Have you created migrations for all your apps? If not, you may well be hitting the problem that the database tables are being created in the wrong order, which will give you this error.

If you have an existing Django 1.7 project, then you need to create the initial migration files, and then fake the initial migration, as described here

https://docs.djangoproject.com/en/1.8/topics/migrations/#adding-migrations-to-apps

Create the migration with

$ python manage.py make migrations your_app_label

And then fake the application

$  python manage.py migrate --fake-initial your_app_label


来源:https://stackoverflow.com/questions/29483119/django-1-8-syncdb-not-working-throwing-a-foreign-key-constraint-error

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!