如果我们将一个字段指定为primary_key
,那么为什么它再次要求为同一个字段指定默认值。下面是我的模型结构。在
class ScatterxBloggerProfile(models.Model):
username = models.CharField(max_length=255L, primary_key=True)
fullname = models.CharField(max_length=255L, null=False)
profileimage = models.TextField(max_length=1000L, null=True, default=None)
description = models.TextField()
role = models.CharField(max_length=255L, blank=True)
level = models.CharField(max_length=255L, null=False)
since = models.CharField(max_length=255L, blank=True)
speciality = models.CharField(max_length=1000L)
writesabout = models.CharField(max_length=1000L)
fbhandle = models.CharField(max_length=255L, unique=True, null=False)
twthandle = models.CharField(max_length=255L, unique=True, null=False)
lkdhandle = models.CharField(max_length=255L, unique=True, null=False)
distributionavailable = models.BooleanField(default=False)
我在前面创建了这个表,没有几个字段,django默认id为primary_key
。现在我添加了一个新的主键。当我尝试迁移时,它会问我:
? The field 'ScatterxBloggerProfile.username' does not have a default specified, yet is NOT NULL.
? Since you are adding this field, you MUST specify a default
? value to use for existing rows. Would you like to:
? 1. Quit now, and add a default to the field in models.py
? 2. Specify a one-off value to use for existing columns now
? Please select a choice:
为什么要指定默认值?在
目前没有回答
相关问题 更多 >
编程相关推荐