解决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;",
        }
posted @ 2022-12-15 19:14  wwwxxx123  阅读(254)  评论(0编辑  收藏  举报