【发布时间】:2014-06-05 20:03:30
【问题描述】:
好的,所以我有一个名为 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: 2
? Please enter Python code for your one-off default value.
? The datetime module is available, so you can do e.g. datetime.date.today()
>>> 0
~ Changed field region on locationmanager.Location
? The field 'Location.manager' 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: 0
! Invalid choice.
? Please select a choice: 2
? Please enter Python code for your one-off default value.
? The datetime module is available, so you can do e.g. datetime.date.today()
>>> 0
~ Changed field manager on locationmanager.Location
Created 0003_auto__chg_field_location_region__chg_field_location_manager.py. You can now apply this migration with: ./manage.py migrate locationmanager
$ sudo python manage.py migrate locationmanager --fake
Running migrations for locationmanager:
- Migrating forwards to 0003_auto__chg_field_location_region__chg_field_location_manager.
> locationmanager:0002_initial
(faked)
> locationmanager:0003_auto__chg_field_location_region__chg_field_location_manager
(faked)
运行测试后,表单向我吐出错误:
IntegrityError at /dash/location/add
locationmanager_location.region_id may not be NULL
我以为我改变了它?我做错了什么?我目前可以做些什么来解决这个问题?
【问题讨论】:
标签: python django django-models django-south