在用户的外键中允许为空。 Django的 [英] Allow null in foreign key to user. Django

查看:303
本文介绍了在用户的外键中允许为空。 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.

这篇关于在用户的外键中允许为空。 Django的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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