Changes between Version 2 and Version 4 of Ticket #34820


Ignore:
Timestamp:
Sep 8, 2023, 1:30:49 AM (16 months ago)
Author:
puc_dong
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #34820

    • Property Resolutionneedsinfo
    • Property Status newclosed
  • Ticket #34820 – Description

    v2 v4  
    22
    33If the models.ForeignObject attribute is used, changing null or blank to generate a new migration record will result in an error message when executing the migrate again
    4 
    5 
    64
    75{{{
     
    4139}}}
    4240
     41**models:**
    4342
    44 https://github.com/django/django/pull/17235
     43{{{
     44# app1:
     45class Model1(models.Model):
     46    name = models.CharField(max_length=50)
     47
     48# app2:
     49class Model2(models.Model):
     50    name = models.CharField(max_length=100, db_index=True)
     51    clu_id = models.BigIntegerField()
     52    scenes = models.ForeignObject(Model1,
     53                                  from_fields=['clu_id'],
     54                                  to_fields=['id'],
     55                                  null=True,
     56                                  related_name='model2_config',
     57                                  on_delete=models.DO_NOTHING)
     58}}}
     59
     60Successfully executed makemigrations&migrate for the first time. When I add blank=True to the scenes field of Model2, and then execute makemigrations and migrate to report an error
     61All migration files:
     62app1.0001_initial.py
     63{{{
     64class Migration(migrations.Migration):
     65
     66    initial = True
     67
     68    dependencies = [
     69    ]
     70
     71    operations = [
     72        migrations.CreateModel(
     73            name='Model1',
     74            fields=[
     75                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
     76                ('name', models.CharField(max_length=50)),
     77            ],
     78        ),
     79    ]
     80
     81}}}
     82app2.0001_initial.py
     83
     84{{{
     85class Migration(migrations.Migration):
     86
     87    initial = True
     88
     89    dependencies = [
     90        ('app_1', '0001_initial'),
     91    ]
     92
     93    operations = [
     94        migrations.CreateModel(
     95            name='Model2',
     96            fields=[
     97                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
     98                ('name', models.CharField(db_index=True, max_length=100)),
     99                ('clu_id', models.BigIntegerField()),
     100                ('scenes', models.ForeignObject(from_fields=['clu_id'], null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='model2_config', to='app_1.model1', to_fields=['id'])),
     101            ],
     102        ),
     103    ]
     104}}}
     105
     106app2.0002_alter_model2_scenes.py
     107
     108{{{
     109class Migration(migrations.Migration):
     110
     111    dependencies = [
     112        ('app_1', '0001_initial'),
     113        ('app_2', '0001_initial'),
     114    ]
     115
     116    operations = [
     117        migrations.AlterField(
     118            model_name='model2',
     119            name='scenes',
     120            field=models.ForeignObject(blank=True, from_fields=('clu_id',), null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='model2_config', to='app_1.model1', to_fields=('id',)),
     121        ),
     122    ]
     123}}}
     124
     125
     126FIX: https://github.com/django/django/pull/17235
Back to Top