| 61 | |
| 62 | In the end, what the current resolution states is that we would have to hand-code the following migration to avoid the failure, which I feel violates the DRY principle, as that is why we allow for abstract models: |
| 63 | {{{ |
| 64 | # -*- coding: utf-8 -*- |
| 65 | from __future__ import unicode_literals |
| 66 | |
| 67 | from django.db import models, migrations |
| 68 | import uuid |
| 69 | |
| 70 | def generate_uuid(apps, schema_editor): |
| 71 | Company = apps.get_model('company', 'Company') |
| 72 | for company in Company.objects.all().iterator(): |
| 73 | company.uuid = uuid.uuid4() |
| 74 | |
| 75 | company.save() |
| 76 | |
| 77 | class Migration(migrations.Migration): |
| 78 | |
| 79 | dependencies = [ |
| 80 | ('main', '0001_initial'), |
| 81 | ] |
| 82 | |
| 83 | operations = [ |
| 84 | migrations.AddField( |
| 85 | model_name='company', |
| 86 | name='uuid', |
| 87 | field=models.UUIDField(editable=False, max_length=32, help_text='Universally unique identifier', null=True, verbose_name='UUID'), |
| 88 | preserve_default=False, |
| 89 | ), |
| 90 | migrations.RunPython( |
| 91 | generate_uuid, |
| 92 | ), |
| 93 | migrations.AlterField( |
| 94 | model_name='company', |
| 95 | name='uuid', |
| 96 | field=models.UUIDField(editable=False, max_length=32, help_text='Universally unique identifier', unique=True, verbose_name='UUID'), |
| 97 | preserve_default=True, |
| 98 | ) |
| 99 | ] |
| 100 | |
| 101 | }}} |