seg*_*lle 5 python django database-migration django-models django-1.9
当我在我的一个项目应用程序上执行迁移时,我收到以下错误:
ValueError:模型的未处理挂起操作:common.shipmentaddress(由fields:catalog.Fulfillment.address引用)
Django 1.9,python 2.7.10
我一直在寻找循环导入,但我不认为这是它
这些是模型:
class ShipmentAddress(models.Model):
recipient_first_name = models.CharField(max_length=50, null=True, blank=True)
recipient_last_name = models.CharField(max_length=50, null=True, blank=True)
street_name = models.CharField(max_length=50)
state = models.ForeignKey(State)
postal_code = models.IntegerField(default=0)
city = models.CharField(max_length=50)
class Meta:
db_table = 'shipment_address'
class Fulfillment(models.Model):
address = models.ForeignKey(ShipmentAddress)
inventory_items = models.ManyToManyField(Item_With_Size, through='Inventory_Item')
class Meta:
verbose_name = 'fulfilment'
verbose_name_plural = 'fulfilments'
db_table = 'fulfilment'
Run Code Online (Sandbox Code Playgroud)
迁移看起来像这样:
class Migration(migrations.Migration):
dependencies = [
('catalog', '0009_auto_20151130_1118'),
]
operations = [
migrations.AlterField(
model_name='fulfillment',
name='address',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='common.ShipmentAddress'),
),
]
class Migration(migrations.Migration):
dependencies = [
('common', '0005_shipmentaddress'),
]
operations = [
migrations.RenameField(
model_name='shipmentaddress',
old_name='recipient_name',
new_name='recipient_first_name',
),
migrations.AddField(
model_name='shipmentaddress',
name='recipient_last_name',
field=models.CharField(blank=True, max_length=50, null=True),
),
]
Run Code Online (Sandbox Code Playgroud)
好,我知道了!
看来迁移过程遍历了我以前的所有迁移,而不仅仅是最后一个......在以前的迁移之一中,有一个错误的外键指针导致了该问题
我修复了旧的迁移,就是这样!
| 归档时间: |
|
| 查看次数: |
5549 次 |
| 最近记录: |