IntegrityError while saving a new item to the postgresql db in django?

北城以北 提交于 2020-01-06 05:05:07

问题


Django saves the data but eventually raises an IntegrityError. If there is an error, why it is saving that data? And I'm sure that the uniqueness property is not violated on that data.

What is going on? Why is that error occurs? and how can I solve that?


回答1:


Most likely your model has a field which doesn't allow null value and you are trying to add object without any value for that field.

If you can Edit your post and add more details (like model & traceback) then you can expect better response.




回答2:


I had the same problem. Using Django 1.3.1 and Sqlite3, I had changed the field properties setting blank=True and null=True, but still got the IntegrityError: "Field may not be null". I tried successive python manage.py syncdb and python manage.py sqlflush with no luck.

I solved it creating a new DB (that is, changing the path to a non-existent filename), and then everything was perfect. Obviously, existing data migration is an issue.



来源:https://stackoverflow.com/questions/3803789/integrityerror-while-saving-a-new-item-to-the-postgresql-db-in-django

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!