允许用户的外键为空.姜戈 [英] Allow null in foreign key to user. Django
本文介绍了允许用户的外键为空.姜戈的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个模型
class Vacancy(models.Model):
user = models.ForeignKey(User, null=True, blank=True, default = None)
name = models.CharField(max_length=64)
在管理员中,我尝试在没有用户的情况下创建一个空缺.它会引发错误club_vacancy.user_id 可能不是 NULL".我是不是做错了什么?
When in admin i try to creat a vacancy without a user. And it throws an error " club_vacancy.user_id may not be NULL". Am i doing something wrong?
推荐答案
club_vacancy.user_id 不能为 NULL
看起来很像来自您的数据库而不是来自 Django 的错误.
Looks very much like an error from your database, rather than from Django.
您很可能在运行 manage.py syncdb
后添加了 null=True
.您需要修改数据库架构以允许该列中有空值.
It seems most likely that you added null=True
after running manage.py syncdb
. You'll need to modify your database schema to allow null values in that column.
这篇关于允许用户的外键为空.姜戈的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文