2013-10-16 34 views
0

我在嘗試添加內容或課程時遇到此錯誤。它工作正常,現在我得到這個錯誤。我已經將它上傳到heroku上,並且它工作正常,只是在本地開發中它不會添加任何內容。有人可以解釋什麼是錯誤的。請同時指定我應該添加哪些附加信息?IntegrityError at/admin/course/course/add/in django

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 
+1

快速和骯髒的解決方案:重置您的開發數據庫。 – abstractpaper

+0

@abstractpaper我不知道後果..我仍然是新的django-dev ..任何干淨的soln。你可能會建議 – user2539745

+0

重置你的開發環境數據庫不應該有嚴重的後果。唯一不利的一面是要重新創建一堆初始數據,你可以用燈具輕鬆解決。 – abstractpaper

回答

4

這是因爲您在完成第一個syncdb後更改了AUTH_USER_MODEL

刪除表「django_admin_log」。然後運行python manage.py syncdb

現在通過對AUTH_USER_MODEL的正確引用重新創建了「django_admin_log」。