django 中 /admin/course/course/add/ 处的 IntegrityError

use*_*745 0 django django-models django-urls django-admin django-views

当我尝试添加内容或课程时出现此错误。它工作正常,现在我收到此错误。我已经将它上传到 heroku 并且它工作正常,只是在本地开发中它不会添加任何内容。有人可以解释一下出了什么问题。请还指定我应该添加哪些附加信息?

IntegrityError at /admin/course/course/add/

insert or update on table "django_admin_log" violates foreign key constraint "django_admin_log_user_id_fkey"
DETAIL:  Key (user_id)=(2) is not present in table "auth_user".

Request Method:     POST
Request URL:    http://127.0.0.1:8888/admin/course/course/add/
Django Version:     1.5.1
Exception Type:     IntegrityError
Exception Value:    

insert or update on table "django_admin_log" violates foreign key constraint "django_admin_log_user_id_fkey"
DETAIL:  Key (user_id)=(2) is not present in table "auth_user".

Exception Location:     /home/vagrant/sai/local/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py in _commit, line 240
Python Executable:  /home/vagrant/sai/bin/python
Python Version:     2.7.3
Run Code Online (Sandbox Code Playgroud)

pan*_*ore 5

这是因为您AUTH_USER_MODEL在执行第一个同步数据库后更改了。

删除表“django_admin_log”。

然后运行python manage.py syncdb

现在使用对 AUTH_USER_MODEL 的正确引用重新创建“django_admin_log”。