| 44 | | https://github.com/django/django/pull/17235 |
| | 43 | {{{ |
| | 44 | # app1: |
| | 45 | class Model1(models.Model): |
| | 46 | name = models.CharField(max_length=50) |
| | 47 | |
| | 48 | # app2: |
| | 49 | class 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 | |
| | 60 | Successfully 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 |
| | 61 | All migration files: |
| | 62 | app1.0001_initial.py |
| | 63 | {{{ |
| | 64 | class 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 | }}} |
| | 82 | app2.0001_initial.py |
| | 83 | |
| | 84 | {{{ |
| | 85 | class 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 | |
| | 106 | app2.0002_alter_model2_scenes.py |
| | 107 | |
| | 108 | {{{ |
| | 109 | class 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 | |
| | 126 | FIX: https://github.com/django/django/pull/17235 |