86👍
Some of my tables were in InnoDB and some were in MyISAM… I changed everything to MyISAM and the problem was solved.
85👍
DATABASES = {
'default': {
...
'OPTIONS': {
"init_command": "SET foreign_key_checks = 0;",
},
}
}
(According to the official doc)
In previous versions of Django, fixtures with forward references (i.e. relations to rows that have not yet been inserted into the database) would fail to load when using the InnoDB storage engine. This was due to the fact that InnoDB deviates from the SQL standard by checking foreign key constraints immediately instead of deferring the check until the transaction is committed. This problem has been resolved in Django 1.4.
- [Django]-How to allow users to change their own passwords in Django?
- [Django]-Django Static files 404
- [Django]-Using django-rest-interface
18👍
To avoid this happening what you can also do is set your STORAGE_ENGINE
in your settings.py
for django >= 1.2
DATABASES = {
'default': {
...
'STORAGE_ENGINE': 'MyISAM / INNODB / ETC'
}
}
for django <= 1.2
DATABASE_STORAGE_ENGINE = "MyISAM / INNODB / ETC"
Please note this is only valid for MySQL
- [Django]-Django-rest-framework 3.0 create or update in nested serializer
- [Django]-Specifying limit and offset in Django QuerySet wont work
- [Django]-Django connection to postgres by docker-compose
8👍
Sometime the reason for this error is trying to save child table first and then save parent.
The solution for this is using.
DATABASES = {
'default': {
...
'OPTIONS': {
"init_command": "SET foreign_key_checks = 0;",
},
}
}
2). Check your database operation flow and make it parent ---> child
- [Django]-Django rest framework change primary key to use a unqiue field
- [Django]-How to get the label of a choice in a Django forms ChoiceField?
- [Django]-Form with CheckboxSelectMultiple doesn't validate
6👍
I ran into this same issue: mmrs151’s solution works, but NB that, for Django <= 1.2
(i.e. before multiple database support), the setting looks like this:
DATABASE_OPTIONS = {"init_command": "SET foreign_key_checks = 0;"}
Worth noting that Ram Rachum seems to have worked around rather than solved the problem: MyISAM doesn’t support transactions at all…
- [Django]-Visual Editor for Django Templates?
- [Django]-Sorting related items in a Django template
- [Django]-Querying django migrations table
-4👍
Another option is to drop the contraint in your MySQL table:
alter table <TABLE_NAME> drop foreign key <CONTRAINT_NAME>;
- [Django]-Django's ModelForm unique_together validation
- [Django]-How do I use a dictionary to update fields in Django models?
- [Django]-Django-way for building a "News Feed" / "Status update" / "Activity Stream"