#24686: Support for Moving a model between two Django apps
-------------------------------+-------------------------------------------
Reporter: Alex Rothberg | Owner: Durval Carvalho
Type: New feature | Status: assigned
Component: Migrations | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+-------------------------------------------
Comment (by Durval Carvalho):
Recently, I’ve been thinking about how reverse migrations might work with
moved model operations.
To illustrate, let’s take an example of a scenario where the following
operations were performed:
{{{
1. The database operation AlterModelTable, renaming the table for the
moved model
1.1. (suppose it is ‘core_category’ → ‘categories_category’)
2. The state operation CreateModel
3. The AlterField of the foreign keys pointing to the moved field
3.1. Supose it is core.category → categories.category
4. The state operation DeleteModel
}}}
By default, the reverse of these operations will be 4 → 3 → 2 ->1.
However, it’s not possible to execute operation number 3 because the table
hasn’t been renamed yet. The reverse operation will try to update the
foreign key field back to core.category and this will be translated to the
core_category table, however this table does not exist in the database at
this point.
As far as I understand, the reverse operation needs to follow the same
sequence as the initial operation (1->2->3->4), but with the fields
reversed, ‘categories_category’ → ‘core_category’ and categories.category
→ core.category.
To resolve this and return to the previous state, one option is to move
the model back to its original app and then run the “makemigrations”
command again. However, keep in mind that this will generate new
migrations instead of reverting the ones that have already been executed.
Does this approach seem reasonable to you?
--
Ticket URL: <https://code.djangoproject.com/ticket/24686#comment:24>
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/01070186a940b1aa-1a043dc2-9af5-4b30-b7fe-324f085d569b-000000%40eu-central-1.amazonses.com.