Python 南方计划移民显然没有';行不通

Python 南方计划移民显然没有';行不通,python,django,django-models,django-south,Python,Django,Django Models,Django South,好的,我有一个名为locationmanager的应用程序,其模型如下: class Location(models.Model): region = models.ForeignKey(Region) 我想把它改成这个 class Location(models.Model): region = models.ForeignKey(Region, blank=True, null=True) 更改后,我运行了一个模式迁移,如下所示: $ python manage.

好的,我有一个名为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
我以为我改变了它?我会做错什么?当前我可以做什么来修复此问题?

您可以指定一个
--false
迁移。伪造您的初始迁移以达到当前状态(更改之前),然后定期迁移

编辑(基于评论): 为了修复迁移,您必须使用回滚到迁移0002

./manage.py migrate locationmanager 0002
迁移0002是伪造的,这没关系,因为您可能不希望south在更改之前更改该州的db方案

现在,您可以使用定期迁移到迁移0003

./manage.py migrate locationmanager
请注意,您始终可以使用查看应用迁移的列表

./manage.py migrate locationmanager --list

什么我在迁移过程中使用了--false,如终端所示。你如何/为什么要--假装最初的迁移?@ApathyBear你为什么要假装迁移?假装它只会将迁移标记为已完成,但在数据库级别上不会起任何作用。我应该怎么做才能取而代之@CésarBustíos@ApathyBear我想您可以返回到以前的迁移并再次迁移,而不需要--false标志