#24630: UUIDField migration
-------------------------------------+-------------------------------------
     Reporter:  lucacorti            |                    Owner:
                                     |  priidukull
         Type:  Bug                  |                   Status:  closed
    Component:  Migrations           |                  Version:  1.8
     Severity:  Normal               |               Resolution:  needsinfo
     Keywords:  uuidfiled            |             Triage Stage:
  migrations                         |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by ollanta):

 Hi, I've stumbled across this issue as well.
 I'm not getting the error with your example either priidukull, so I
 reduced the code I had to a small example that still exhibits the bug (in
 both django 1.7 and 1.8, but only in psql, not sqlite)

 0001_initial.py :
 {{{
 # -*- coding: utf-8 -*-
 from __future__ import unicode_literals

 from django.db import models, migrations
 from django.conf import settings


 class Migration(migrations.Migration):

     dependencies = []

     operations = [
         migrations.CreateModel(
             name='Parent',
             fields=[
                 ('id', models.AutoField(verbose_name='ID',
 serialize=False, auto_created=True, primary_key=True)),
             ],
         ),
         migrations.CreateModel(
             name='Child',
             fields=[
                 ('id', models.AutoField(verbose_name='ID',
 serialize=False, auto_created=True, primary_key=True)),
                 ('boolfield', models.BooleanField(default=True)),
                 ('parent', models.ForeignKey(to='example.Parent')),
             ],
         ),

     ]
 }}}
 0002_add_data.py:

 {{{
 # -*- coding: utf-8 -*-
 from __future__ import unicode_literals

 from django.db import models, migrations


 def add_data(apps, schema_editor):
     Parent = apps.get_model("example", "Parent")
     p = Parent(1)
     p.save()

     Child = apps.get_model("example", "Child")
     c = Child(1, parent=p, boolfield=True)
     c.save()


 class Migration(migrations.Migration):

     dependencies = [
         ('example', '0001_initial'),
     ]

     operations = [
         migrations.RunPython(
             add_data
         )
     ]

 }}}
 0003_change_field_type.py:

 {{{
 # -*- coding: utf-8 -*-
 from __future__ import unicode_literals

 from django.db import models, migrations


 def convert_field(apps, schema_editor):
     Child = apps.get_model("example", "Child")
     for c in Child.objects.all():
         c.textchoicefield = 'true' if c.boolfield else 'false'
         c.save()


 class Migration(migrations.Migration):

     dependencies = [
         ('example', '0002_add_data'),
     ]

     operations = [
         migrations.AddField(
             model_name='child',
             name='textchoicefield',
             field=models.TextField(default=b'none', choices=[(b'true',
 b'True'), (b'false', b'False'), (b'none', b'None')]),
             preserve_default=True,
         ),
         migrations.RunPython(convert_field),
         migrations.RemoveField(
             model_name='child',
             name='boolfield',
         ),
     ]

 }}}

 If I move RemoveField out of the last migration and into its own, it all
 works fine.

--
Ticket URL: <https://code.djangoproject.com/ticket/24630#comment:8>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/067.0a96fc4645b4b91fca4a8a7d98af68af%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to