#34665: An OperationalError is thrown when using SQLite database in Django 4.1
during 'migrate', while it works normally on versions below 4.1 and also
works normally on MySQL.
-------------------------------------+-------------------------------------
Reporter: Amchii | Owner: nobody
Type: Bug | Status: new
Component: Database | Version: 4.2
layer (models, ORM) |
Severity: Normal | Keywords: sqlite3
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
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?
--
Ticket URL: <https://code.djangoproject.com/ticket/34665>
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/01070188d254859b-6902d20c-4e74-428c-a7d3-cf3c434bccdd-000000%40eu-central-1.amazonses.com.