解决ORM错误:django.db.utils.IntegrityError: (1452, 'Cannot add or update a child row: a foreign key constraint fails
# 修改settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'test',
'HOST':'127.0.0.1',
'PORT':3306,
'USER':'root',
'PASSWORD':'123',
'OPTIONS': {
"init_command": "SET foreign_key_checks = 0;",
}
}
}
# 添加以下代码,取消外键检查
'OPTIONS': {
"init_command": "SET foreign_key_checks = 0;",
}