今天在做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
