django 存储数据时 报 IntergrityErrror错误

来源:互联网 发布:意大利脱欧 知乎 编辑:程序博客网 时间:2024/06/06 01:37

Django saves the data but eventually raises an IntegrityError. Django中保存的数据,但最终引发一个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?我怎样才能解决这个问题呢?

来源:http://stackoverflow.com/questions/3803789/integrityerror-while-saving-a-new-item-to-the-postgresql-db-in-django
  • 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.如果您可以编辑您的文章和添加更多的细节(如模型及追踪),那么你可以期待更好的响应。

  • 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".使用Django 1.3.1和SQLite3,我改变了空白= True和空的字段属性设置为True,但仍然有IntegrityError:“字段不能为空”。 I tried successive python manage.py syncdb andpython manage.py sqlflush with no luck.我试过连续python manage.py syncdbpython manage.py sqlflush没有运气。

    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.显然,现有的数据迁移是一个问题。

原创粉丝点击