python - IntegrityError at/***/(1048, "Column ' ** *' cannot be null") 在 python django

标签 python django

您好,我收到此错误是因为我的 additional user info model 中有一个字段(user = models.OneToOneField(User)) 我在注册时没有填写(因为我想让用户稍后填写)。

除了在数据库中允许空字段外,我想知道是否有任何方法可以解决这个问题?

干杯

最佳答案

尝试

user = models.OneToOneField(User, null=True, blank=True)

然后重新创建您的数据库。 您可以在 https://docs.djangoproject.com/en/1.4/ref/models/fields/#null 上找到更多信息

否则你可以使用代理模型:

class UserExtraInfo(User):
#here your extra fields

在这种情况下,您不需要与 User 同时创建 UserExtraInfo 实例。 在 https://docs.djangoproject.com/en/1.4/topics/db/models/#model-inheritance 上阅读更多内容

关于python - IntegrityError at/***/(1048, "Column ' ** *' cannot be null") 在 python django,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12036400/

相关文章:

python - 从 View 导入数据后如何将下拉数据分配给字段

django - 如何更改modelForm选择字段的empty_label?

python - 检查 django 权限或运算符(operator)?

javascript - 属性错误: 'NoneType' object has no attribute 'is_active'

python - 如何以完整的位深度保存多个子图

python - POSTGRES - 具有多个连接的高效 SELECT 或 INSERT

Python 八进制转义字符串

python - 在 Python 中四舍五入到给定的数字

python - django app_details() 收到意外的关键字参数 'slug' 错误

python - 如何管理django中的锁写机制