﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
33932	Altering AutoFields with renaming a column crashes on PostgreSQL.	Benoît Vinot	Benoît Vinot	"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..."	Bug	closed	Migrations	4.1	Release blocker	fixed		Florian Apolloner	Ready for checkin	1	0	0	0	0	0
