I have renamed the field `id` into `base_ptr` (`Base` is the new parent
table) and then, in another migration file, I try to make this column to
be a 1 to 1 column. To do that, I have in my migration an operation like
this
{{{
migrations.AlterField(
model_name="son",
name="base_ptr",
field=models.OneToOneField(
auto_created=True,
on_delete=django.db.models.deletion.CASCADE,
parent_link=True,
primary_key=True,
serialize=False,
to="app.Base",
),
),
}}}
which leads to this SQL code
{{{
BEGIN;
--
-- Alter field base_ptr on son
--
ALTER TABLE "app_son" RENAME COLUMN "base_ptr" TO "base_ptr_id";
ALTER TABLE "app_son" ALTER COLUMN "base_ptr" DROP IDENTITY IF EXISTS;
ALTER TABLE "app_son" ALTER COLUMN "base_ptr_id" TYPE integer;
DROP SEQUENCE IF EXISTS "app_son_base_ptr_id_seq" CASCADE;
ALTER TABLE "app_son" ADD CONSTRAINT
"app_son_base_ptr_id_d3673d48_fk_app_base" FOREIGN KEY ("base_ptr_id")
REFERENCES "app_base" ("id") DEFERRABLE INITIALLY DEFERRED;
--
}}}
This SQL code fails because the second line (`DROP IDENTITY EXISTS`)
references the `base_ptr` column which has been renamed into `base_ptr_id`
by the first line...
--
Ticket URL: <https://code.djangoproject.com/ticket/33932>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
Comment (by Mariusz Felisiak):
Can you provide a sample project to reproduce? This transition is quite
tricky.
--
Ticket URL: <https://code.djangoproject.com/ticket/33932#comment:1>