Re: [Django] #35373: GeneratedField alteration fail on SQLite due table remake data insertion (was: db_index=True on a Generated Column generates failing migrations)

7 views
Skip to first unread message

Django

unread,
Apr 14, 2024, 1:10:14 AM4/14/24
to django-...@googlegroups.com
#35373: GeneratedField alteration fail on SQLite due table remake data insertion
-------------------------------------+-------------------------------------
Reporter: Moshe Dicker | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 5.0
(models, ORM) |
Severity: Release blocker | Resolution:
Keywords: migrations,db | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):

* easy: 1 => 0
* severity: Normal => Release blocker
* stage: Unreviewed => Accepted
* summary: db_index=True on a Generated Column generates failing
migrations =>
GeneratedField alteration fail on SQLite due table remake data
insertion

Comment:

Thank you for your report, a traceback and a description of the backend
you are using would have been appreciated.

This looks like a problem isolated to SQLite due to the way
`_remake_table` doesn't exclude generated fields from its `INSERT INTO
new_table SELECT ... FROM old_table` at table rename (a necessary step
since SQLite doesn't support most table operations).

{{{#!diff
diff --git a/django/db/backends/sqlite3/schema.py
b/django/db/backends/sqlite3/schema.py
index 495714a894..32f4f08459 100644
--- a/django/db/backends/sqlite3/schema.py
+++ b/django/db/backends/sqlite3/schema.py
@@ -150,7 +150,9 @@ def is_self_referential(f):
body.pop(old_field.name, None)
mapping.pop(old_field.column, None)
body[new_field.name] = new_field
- if old_field.null and not new_field.null:
+ if new_field.generated:
+ pass
+ elif old_field.null and not new_field.null:
if new_field.db_default is NOT_PROVIDED:
default =
self.prepare_default(self.effective_default(new_field))
else:
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/35373#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
Reply all
Reply to author
Forward
0 new messages