fix incorrect removal of uniqueness constraint code field
This commit is contained in:
parent
28bf782731
commit
ea2eb666d4
|
|
@ -6,6 +6,16 @@ import django.db.models.deletion
|
|||
import utils.models
|
||||
|
||||
|
||||
def copy_country_code(apps, schema_editor):
|
||||
Country = apps.get_model('location', 'Country')
|
||||
to_update = []
|
||||
for country in Country.objects.all():
|
||||
if country.code:
|
||||
country.code_2 = country.code
|
||||
to_update.append(country)
|
||||
Country.objects.bulk_update(to_update, ['code_2', ])
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
|
|
@ -63,9 +73,21 @@ class Migration(migrations.Migration):
|
|||
name='region',
|
||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='location.Region', verbose_name='parent region'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
# -- fix incorrect removal of uniqueness constraint code field
|
||||
migrations.AddField(
|
||||
model_name='country',
|
||||
name='code_2',
|
||||
field=models.CharField(max_length=255, null=True)
|
||||
),
|
||||
migrations.RunPython(copy_country_code, migrations.RunPython.noop),
|
||||
migrations.RemoveField(
|
||||
model_name='country',
|
||||
name='code',
|
||||
field=models.CharField(max_length=255, verbose_name='Code'),
|
||||
),
|
||||
migrations.RenameField(
|
||||
model_name='country',
|
||||
old_name='code_2',
|
||||
new_name='code',
|
||||
)
|
||||
# fix incorrect removal of uniqueness constraint code field --
|
||||
]
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user