南:当提供有效的一次性默认值时,为什么"column <colname>包含空值"错误

tam*_*are 4 django django-south

本来,模型属性位置项目类的定义如下所示:

location = models.ForeignKey('Location', related_name='+', null=True, on_delete=models.SET_NULL)
Run Code Online (Sandbox Code Playgroud)

然后重新定义为:

location = models.ForeignKey('Location', related_name='+', on_delete=models.PROTECT)
Run Code Online (Sandbox Code Playgroud)

由于定义的变化,我执行了South的模式移植.南回应

字段'Item.location'没有指定默认值,但是NOT NULL.由于您要使此字段不可为空,因此您必须指定用于现有行的默认值.

我选择了'2'并提供了现有位置的PK(整数).

但是当我运行迁移时,我收到以下错误:

django.db.utils.IntegrityError:列"location_id"包含空值

我不明白为什么在提供有效的默认位置PK时出现此错误.这真是令人难以置信.请帮忙〜谢谢.

迁移规范:

def forwards(self, orm):
    # Changing field 'Item.location'
    db.alter_column('lend_borrow_item', 'location_id', self.gf('django.db.models.fields.related.ForeignKey')(default=11, to=orm['app_name.Location']))
def backwards(self, orm):
    # Changing field 'Item.location'
    db.alter_column('lend_borrow_item', 'location_id', self.gf('django.db.models.fields.related.ForeignKey')(null=True, to=orm['app_name.Location']))

models = {
    'app_name.location': {
        'Meta': {'ordering': "['name']", 'object_name': 'Location'},
        'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
        'name': ('django.db.models.fields.CharField', [], {'max_length': '20'})
    },
    'lend_borrow.item': {
        'Meta': {'object_name': 'Item'},
        'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
        'location': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'+'", 'to': "orm['app_name.Location']"}),
        'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
    }
}
Run Code Online (Sandbox Code Playgroud)

tam*_*are 5

这个问题似乎是由South Defect#627引起的