今天在做mxonline項目時,注冊了使用者表進admin後,想在背景添加一個使用者試試,結果出現了錯誤,經過一番搜尋發現以下兩個解決方法,不過我隻用了一種
報錯資訊:
IntegrityError: (1452, u'Cannot add or update a child row: a foreign key constraint fails (`mxonline`.`django_admin_log`, CONSTRAINT `django_admin_log_user_id_c564eba6_fk_auth_user_id` FOREIGN KEY (`user_id`) REFERENCES `auth_user` (`id`))')
具體解決方法:
方法1:在settings.py檔案中,資料庫的配置參數中設定關閉外鍵檢查
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': "mxonline",
'USER': "root",
'PASSWORD': "123",
'HOST': '',
'OPTIONS': {
"init_command": "SET foreign_key_checks = 0;",
}
}
}
方法2:将userprofile表中的資料複制 到auth_user表中,即可生成新使用者。
參考連結:
https://www.imooc.com/wenda/detail/382273
https://www.cnblogs.com/shijieli/p/10529419.html
轉載于:https://www.cnblogs.com/welisit/p/10850641.html