#34881: migrate crashes when renaming model referenced twice by
ManyToManyField.through model on SQLite.
----------------------------+----------------------------------------
Reporter: dennisvang | Owner: Jase Hackman
Type: Bug | Status: assigned
Component: Migrations | Version: dev
Severity: Normal | Resolution:
Keywords: sqlite | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------+----------------------------------------
Comment (by Jase Hackman):
I spent some time digging into this today.
To account for the unique nature of sqlite a `_remake_table()`
[https://github.com/jasehackman/django/blob/2abf417c815c20f41c0868d6f66520b32347106e/django/db/backends/sqlite3/schema.py#L75
link] method was added to recreate the table under the various conditions
under which it is required for table schema changes
[https://www.sqlite.org/lang_altertable.html#caution sqlite docs].
The problem is that the code is not aware of previous calls of
`_remake_table()` or if multiple will be required for a single table.
To fix this I am going to try to aggregate all of the alter statements
into a single call, resulting in a single create statement.
To accomplish this I added an `alter_fields()` method to
`BaseDatabaseSchemaEditor` that is passed a list of tuples to of the
fields to be updated. It then loops over those fields to call the original
`alter_field()` method. So far the new method is only being called in
`RenameModel`.
[https://github.com/django/django/commit/e382a37f1b90bfdac7b22ed1a4e800b7a37cd28a
See commit with current progress]
I next plan override this new method in the sqlite `DatabaseSchemaEditor`
to allow for new logic that aggregates the alter statements into a single
remake of the table. I'm going to continue down this path unless anyone
has feedback, or recommendations towards a different approach.
--
Ticket URL: <https://code.djangoproject.com/ticket/34881#comment:15>
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/0107018b4a706d00-cccfed7a-4124-4740-a489-e1a3de94cee6-000000%40eu-central-1.amazonses.com.