Django Migrations and UUID Fields

referral_code = models.UUIDField(default=uuid.uuid4)
# -*- coding: utf-8 -*-
# Generated by Django 1.11.5 on 2018-02-26 19:29
from __future__ import unicode_literals

from django.db import migrations, models
import uuid


def create_uuid(apps, schema_editor):
Institution = apps.get_model('consortial_billing', 'Institution')
for inst in Institution.objects.all():
inst.referral_code = uuid.uuid4()
inst.save()


class Migration(migrations.Migration):

dependencies = [
('consortial_billing', '0031_supportlevel_description'),
]

operations = [
migrations.AddField(
model_name='institution',
name='referral_code',
field=models.UUIDField(blank=True, null=True),
),
migrations.RunPython(create_uuid),
migrations.AlterField(
model_name='institution',
name='referral_code',
field=models.UUIDField(default=uuid.uuid4, unique=True)
)
]

 by the author.

--

--

Pub Tech developer for Birkbeck CTP

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Andy Byers

Andy Byers

Pub Tech developer for Birkbeck CTP