所以我有一个用户可以发布关于效果的评论,我链接我的模型,我不断得到不可空的错误,无论我尝试过什么。每个人都说它需要有null = True。它不工作大声笑。我在这里看不到什么?
这是官方错误:
django.db.utils.IntegrityError: NOT NULL constraint failed: effect_modules_comment__new.author_id
我的模特:
class Effect_module(models.Model):
created_at = models.DateTimeField(auto_now_add=True)
title = models.CharField(max_length=255)
description = models.TextField()
html = models.TextField(default='')
css = models.TextField(default='')
js = models.TextField(default='')
up_votes = models.IntegerField()
down_votes = models.IntegerField()
effect_author = models.ManyToManyField('UserProfile')
class UserProfile(models.Model):
user = models.OneToOneField(User)
effects = models.ManyToManyField(Effect_module)
class Comment(models.Model):
comment_author = models.ForeignKey(User, null=True)
comment = models.TextField(default='No Comment Here')
effect_object = models.ForeignKey(Effect_module)
答案 0 :(得分:3)
删除所有迁移脚本。添加null=True
表示数据库中可以为NULL,blank=True
表示可以在表单中留空。
然后
python manage.py makemigrations
python manage.py migrate