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()

class Migration(migrations.Migration):

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

operations = [
field=models.UUIDField(blank=True, null=True),
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

More from Medium

Connect Celery and RabbitMQ with Django

integrate celery and rabbitmq to django

Handle MEDIA files in production — Django

floppy disks and Django media

Playing around with Django JWT

Django Models Unchained.