其他分享
首页 > 其他分享> > 1452, 'Cannot add or update a child row: a foreign key constraint fails

1452, 'Cannot add or update a child row: a foreign key constraint fails

作者:互联网

(1452, 'Cannot add or update a child row: a foreign key constraint fails (`mxproject`.`django_admin_log`, 
CONSTRAINT `django_admin_log_user_id_c564eba6_fk_auth_user_id` FOREIGN KEY (`user_id`) REFERENCES `auth_user` (`id`))')

  这时候需要在setting文件的databases中添加以下代码取消外键检查

 

 

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'zhq2',
        'USER': 'root',
        'PASSWORD': '211314',
        'HOST': '127.0.0.1',
        'PORT': 3306,
        # 取消外键的检查(admin后台添加数据会报错)
        'OPTIONS': {
            "init_command": "SET foreign_key_checks = 0;",
        }
    }
}

 

  

 

标签:fails,constraint,admin,django,user,key,foreign,id
来源: https://www.cnblogs.com/zhanghongqi/p/11284208.html