Migration 1
{{{
class Migration(migrations.Migration):
dependencies = [
('app', '0028_xxxx'),
]
operations = [
migrations.AlterField(
model_name='model',
name='uuid',
field=models.CharField(db_index=True, max_length=36,
blank=True, null=True, unique=False),
),
]
}}}
This migration runs the following SQL:
{{{
ALTER TABLE "table" ALTER COLUMN "uuid" DROP NOT NULL; (params [])
CREATE INDEX "table_uuid_42f8156744ac727f_uniq" ON "table" ("uuid");
(params [])
CREATE INDEX "table_uuid_42f8156744ac727f_like" ON "table" ("uuid"
varchar_pattern_ops); (params [])
}}}
Migration 2
{{{
def fill_uuids(apps, schema_editor):
models = apps.get_model('app', 'model')
models.objects.all().update(uuid=UUID1Now()) # Using postgres to
generate uuid 1's
def reverse_uuids(apps, schema_editor):
models = apps.get_model('app', 'model')
models.objects.all().update(uuid='')
class Migration(migrations.Migration):
dependencies = [
('app', '0029_xxxxx'),
]
operations = [
migrations.RunPython(fill_uuids, reverse_code=reverse_uuids),
migrations.AlterField(
model_name='model',
name='uuid',
field=models.CharField(db_index=True, max_length=36,
blank=True, null=False, unique=True),
),
]
}}}
Migration 2 generates this SQL:
{{{
(0.146) UPDATE "table" SET "uuid" = uuid_generate_v1(); args=()
ALTER TABLE "table" ALTER COLUMN "uuid" SET DEFAULT %s, ALTER COLUMN
"uuid" SET NOT NULL; (params [u''])
(0.002) ALTER TABLE "table" ALTER COLUMN "uuid" SET DEFAULT '', ALTER
COLUMN "uuid" SET NOT NULL; args=[u'']
ALTER TABLE "table" ADD CONSTRAINT "table_uuid_42f8156744ac727f_uniq"
UNIQUE ("uuid"); (params [])
(0.010) ALTER TABLE "table" ADD CONSTRAINT
"table_uuid_42f8156744ac727f_uniq" UNIQUE ("uuid"); args=[]
}}}
That causes this exception `django.db.utils.ProgrammingError: relation
"table_uuid_42f8156744ac727f_uniq" already exists`
--
Ticket URL: <https://code.djangoproject.com/ticket/26782>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Old description:
New description:
Migration 1
{{{
class Migration(migrations.Migration):
}}}
Migration 2
A work around is to remove the `db_index` in migration 1.
--
--
Ticket URL: <https://code.djangoproject.com/ticket/26782#comment:1>
* status: new => closed
* resolution: => duplicate
Comment:
Duplicate of #25694.
--
Ticket URL: <https://code.djangoproject.com/ticket/26782#comment:2>