user2307087
user2307087

Reputation: 423

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

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)?

Upvotes: 2

Views: 1028

Answers (2)

Rachel
Rachel

Reputation: 2894

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

Upvotes: 0

Wagh
Wagh

Reputation: 4316

Try this

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

Upvotes: 3

Related Questions