gpt4 book ai didi

python - 尝试执行迁移时模型未处理的挂起操作

转载 作者:太空狗 更新时间:2023-10-30 00:54:49 25 4
gpt4 key购买 nike

当我对我的一个项目应用程序执行迁移时,出现以下错误:

ValueError:模型未处理的挂起操作: common.shipmentaddress(由字段引用: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'

迁移看起来像这样:

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),
),
]

最佳答案

好的,我明白了!

似乎迁移过程遍历了我之前的所有迁移,而不仅仅是最后一个......在之前的一个迁移中,有一个错误的外键指针导致了这个问题

我修复了旧的迁移,仅此而已!

关于python - 尝试执行迁移时模型未处理的挂起操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34267231/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com