From bd648d0cb19d47bc03c3475540087f1f38874da5 Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Thu, 5 May 2016 23:17:32 -0400 Subject: [PATCH] Postgresql needs typecasting for turning char fields into native UUID fields. Conditionally run the necesary SQL for this to happen. GitLab issue #266 Thanks to Baptiste GAULLET @bat79a for finding the solution. --- .../migrations/0032_auto_20160315_0537.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/mayan/apps/documents/migrations/0032_auto_20160315_0537.py b/mayan/apps/documents/migrations/0032_auto_20160315_0537.py index 0e413efaca..903850a24c 100644 --- a/mayan/apps/documents/migrations/0032_auto_20160315_0537.py +++ b/mayan/apps/documents/migrations/0032_auto_20160315_0537.py @@ -1,12 +1,12 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import migrations, models import uuid +from django.db import connection, migrations, models + class Migration(migrations.Migration): - dependencies = [ ('documents', '0031_convert_uuid'), ] @@ -18,3 +18,13 @@ class Migration(migrations.Migration): field=models.UUIDField(default=uuid.uuid4, editable=False), ), ] + + def __init__(self, *args, **kwargs): + super(Migration, self).__init__(*args, **kwargs) + + if connection.vendor == 'postgresql': + self.operations.insert( + 0, migrations.RunSQL( + 'ALTER TABLE documents_document ALTER COLUMN uuid SET DATA TYPE UUID USING uuid::uuid;' + ) + )