Migration dependency not added when field is altered

22 zobrazení
Přeskočit na první nepřečtenou zprávu

Erin Masatsugu

nepřečteno,
27. 5. 2020 22:02:3427.05.20
komu: Django users
If I have this a model in app A:
class AppAModel(models.Model):
    name = models.CharField(max_length=50, default="")

and this model in app B:
class AppBModel(models.Model):
    name = models.CharField(max_length=50, default="")

and a I add a foreign key to AppAModel in app C:
class AppCModel(models.Model):
    my_field = models.ForeignKey(AppAModel, on_delete=models.CASCADE)

the generated migration file correctly adds a dependency from app C to app A:
class Migration(migrations.Migration):

    dependencies = [
        ('app_a', 'XXXX_app_a_migration'),
        ('app_c', 'XXXX_app_c_migration'),
    ]

    operations = [
        migrations.CreateModel(
            name='AppCModel',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('my_field', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='ncm.AppAModel')),
            ],
        ),
    ]

However, if I then update my_field to instead have a foreign key to AppBModel, django doesn't add a migration dependency from app C to app B:
class Migration(migrations.Migration):

    dependencies = [
        ('app_c', 'XXXX_app_c_migration'),
    ]

    operations = [
        migrations.AlterField(
            model_name='appcmodel',
            name='my_field',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='metals.AppBModel'),
        ),
    ]

I saw the response here https://groups.google.com/forum/#!searchin/django-users/migration$20dependency%7Csort:date/django-users/-h9LZxFomLU/ry_yeWGfDQAJ so I don't believe this is expected behavior, but can someone confirm?

Thank you!
Erin

Durai pandian

nepřečteno,
28. 5. 2020 0:44:1628.05.20
komu: django...@googlegroups.com
When you make any changes to the field, AlterField will be added rather than AddField.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/48ab3732-f667-472f-a678-ca9f082315da%40googlegroups.com.


--
Thanks & Regards,
Durai pandian
Mobile  :
+91-9611051220
Email    : ddp...@gmail.com

Erin Masatsugu

nepřečteno,
28. 5. 2020 10:46:5228.05.20
komu: Django users
I understand that -- my question is why the AlterField operation in this case didn't add a migration dependency.


On Wednesday, May 27, 2020 at 6:44:16 PM UTC-10, Durai pandian wrote:
When you make any changes to the field, AlterField will be added rather than AddField.

To unsubscribe from this group and stop receiving emails from it, send an email to django...@googlegroups.com.
Odpovědět všem
Odpověď autorovi
Přeposlat
0 nových zpráv