添加到models.py后“NOT NULL约束失败" [英] 'NOT NULL constraint failed' after adding to models.py

查看:29
本文介绍了添加到models.py后“NOT NULL约束失败"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 userena 并将以下行添加到我的 models.py

I'm using userena and after adding the following line to my models.py

zipcode = models.IntegerField(_('zipcode'),
                                   max_length=5)

我在点击注册表上的提交按钮后收到以下错误:

I get the following error after I hit the submit button on th signup form:

IntegrityError at /accounts/signup/
NOT NULL constraint failed: accounts_myprofile.zipcode

我的问题是这个错误是什么意思,这与 Userena 有关系吗?

My question is what does this error mean, and is this related to Userena?

推荐答案

您必须创建一个迁移,您将在其中为新字段指定默认值,因为您不希望它为空.如果不需要 null,只需添加 null=True 并创建并运行迁移.

You must create a migration, where you will specify default value for a new field, since you don't want it to be null. If null is not required, simply add null=True and create and run migration.

这篇关于添加到models.py后“NOT NULL约束失败"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆