﻿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
34665	CreateModel with manually added RenameField crashes on SQLite.	Amchii	nobody	"When using the SQLite database to perform migrations in Django 4.1 and 4.2, an OperationalError is thrown; however, it works normally on versions below 4.1 and also works normally on MySQL.

Here's the reproduction steps(use sqlite3):

1. models.py:
{{{
from django.db import models


class Person(models.Model):
    class Meta:
        db_table = ""person""

    name = models.CharField(max_length=32)
    age = models.IntegerField()
    open_id = models.PositiveBigIntegerField(db_index=True)
}}}

2. run python manage.py makemigrations and it generates
0001_initial.py:

{{{
# Generated by Django 4.2.2 on 2023-06-19 06:10

from django.db import migrations, models


class Migration(migrations.Migration):
    initial = True

    dependencies = []

    operations = [
        migrations.CreateModel(
            name=""Person"",
            fields=[
                (
                    ""id"",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name=""ID"",
                    ),
                ),
                (""name"", models.CharField(max_length=32)),
                (""age"", models.IntegerField()),
                (""open_id"", models.PositiveBigIntegerField(db_index=True)),
            ],
            options={
                ""db_table"": ""person"",
            },
        ),
    ]
}}}
3. rename field `open_id` -> `open_uid`, edit 0001_initial.py and add this line:

{{{
migrations.RenameField(
            model_name=""person"",
            old_name=""open_id"",
            new_name=""open_uid"",
        ),
}}}
4. remove field 'age' and run python manage.py makemigrations, it generates 0002_remove_person_age.py:

{{{
# Generated by Django 4.2.2 on 2023-06-19 06:12

from django.db import migrations


class Migration(migrations.Migration):
    dependencies = [
        (""myapp"", ""0001_initial""),
    ]

    operations = [
        migrations.RemoveField(
            model_name=""person"",
            name=""age"",
        ),
    ]

}}}
5. run python manage.py migrate, it raises:

django.db.utils.OperationalError: error in index person_open_id_aac92076 after drop column: no such column: open_id


I encountered this issue while testing after upgrading an old project from Django version to 4.1. Although I manually added a line instead of using makemigrations when renaming the 'open_id' field, it should still work properly?
"	Bug	closed	Database layer (models, ORM)	4.2	Normal	invalid	sqlite3		Unreviewed	0	0	0	0	0	0
