#33932: Error in migration with version 4.1
----------------------------------------+------------------------
Reporter: BenoƮt Vinot | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 4.1
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
----------------------------------------+------------------------
Hi, here is my problem. I have an independent table with a `id` primary
key. I would like this table to inherit from a new parent table. I have
generated migrations which work with Django version 4.0.7 but fail with
Django 4.1.
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.
--
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 view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/01070182ab37eed5-330e0039-4218-4087-b9ba-4d8b8f0b5fb7-000000%40eu-central-1.amazonses.com.