Pending unfinished operations for models when trying to migrate

When I migrate to one of my projects, I get the following error:

ValueError: raw pending operations for models: common.shipmentaddress (by field: catalog.Fulfillment.address)

Django 1.9, python 2.7.10

I was looking for cyclic imports, but I don’t think that it is he

These are the models:

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'

Migrations are as follows:

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),
        ),
    ]
+4
source share
2 answers

OK I understood!

, , ... , .

!

+4

, , Django ForeignKey, , , - . .

( ):

    migrations.AddField(
                model_name='my_model',
                name='my_fk',
                field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='+', to='my_app.old_model_name'),
            )

, old_model_name new_model_name, :

    migrations.AlterField(
                model_name='my_model',
                name='my_fk',                
                field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='+', to='my_app.new_model_name'),
            )

- AlterField AddField to ForeignKey.

Django 1.9.12.

+2

Source: https://habr.com/ru/post/1619875/


All Articles