【发布时间】:2014-06-05 18:17:15
【问题描述】:
好的,所以我有一个名为 locationmanager 的应用程序,其模型如下所示:
class Location(models.Model):
region = models.ForeignKey(Region)
我想把它改成这个
class Location(models.Model):
region = models.ForeignKey(Region, blank=True, null=True)
所以我运行了架构迁移并收到以下信息:
$ python manage.py schemamigration locationmanager --auto
? The field 'Location.region' does not have a default specified, yet is NOT NULL.
? Since you are making this field nullable, you MUST specify a default
? value to use for existing rows. Would you like to:
? 1. Quit now.
? 2. Specify a one-off value to use for existing columns now
? 3. Disable the backwards migration by raising an exception; you can edit the migration to fix it later
? Please select a choice:
这让我很困惑。是的,我已经阅读了南方的文档。
首先,为什么它说
'Location.region' does not have a default specified, yet is NOT NULL.我对该字段所做的更改使其成为空值,这是什么情况?一个解释会很棒。为什么需要指定默认值?一旦我指定了这个默认值,它在哪里?在 SQL 表中?如果我有现有数据,这是否重要,或者这仅仅是为了方案本身?
3.我有点理解选项 1,2,但选项 3 究竟会做什么?为什么有用?
非常感谢。
【问题讨论】:
标签: python django django-models django-south