当我尝试为我的一个模型添加空字段的可能性时,出现以下错误消息:“ TypeError: init ()得到了意外的关键字参数'allow_blank'” >
我尝试做的是在TextField和CharField中都添加关键字“ allow_blank = True”。两种情况下都存在相同的错误。
from django.db import models
from django.contrib.auth.models import User
class Set(models.Model):
pass
class Chat(models.Model):
setID = models.ForeignKey(Set, on_delete=models.CASCADE)
chatID = models.CharField(max_length=100)
class Message(models.Model):
chat = models.ForeignKey(Chat, on_delete=models.CASCADE)
chatID = models.CharField(max_length=100)
messageID = models.CharField(max_length=100)
createdDate = models.DateTimeField()
createdBy = models.CharField(max_length=1000)
author = models.CharField(max_length=1000)
messageDate = models.DateTimeField()
text = models.TextField()
class Category(models.Model):
name = models.CharField(max_length=100)
class Tag(models.Model):
user = models.ForeignKey(User, related_name="tags",
on_delete=models.CASCADE, null=True)
category = models.ForeignKey(Category, on_delete=models.DO_NOTHING)
value = models.TextField(max_length=None, allow_blank=True)
message = models.ForeignKey(Message, on_delete=models.CASCADE)
created = models.DateTimeField(auto_now_add=True)
flagged = models.BooleanField(default=False)
我想做的是在Tag模型中允许一个空字段,因此,如果有更好的方法,请告知。
答案 0 :(得分:1)
在Django中,没有什么叫allow_blank
,只有blank
value = models.TextField(max_length=None, blank=True)