#24686: Support for Moving a model between two Django apps
-------------------------------+------------------------------------
Reporter: Alex Rothberg | Owner: Bhuvnesh
Type: New feature | Status: assigned
Component: Migrations | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+------------------------------------
Comment (by Shai Berger):
Replying to [comment:33 Maarten Nieber]:
> I've been struggling with this issue for a while, and came upon an
extremely simple (though not perfect) solution. Things seem to keep
working fine if I move the model code to a new django app, and set the
"app_label" field in the Meta class to point to the old django app.
>
> I have two questions:
>
> - is this totally fine to do, and expected to work?
I disagree with Bhuvnesh above: I expect this to work, in the sense that
your project should continue to run, and no migration will be necessary.
But it's "cheating" -- the model's ''code'' has been moved to a different
''file'', but the model is still in the old app for all other purposes: If
you make a change in it, the migration will still be created in the old
app. If you try to remove the old app, things will break. Anywhere you'd
want to reference it by name (e.g. in a Foreign Key definition), you'll
need to refer to it with the label specified in its meta, not the label of
the app in whose {{{ models.py }}} it is defined.
> - should we explain in the Docs that this is a simple and effective way
to move a model?
... and the above is why I think we shouldn't. I expect doing this --
creating a discrepancy between the model's import path and the way Django
treats it -- is likely to cause problems and confusion, negating the value
of the refactoring that is achieved by the move.
The ability to change the app-label in the {{{ Meta }}} is mostly useful
in cases where you want a model defined outside of its app's {{{ models.py
}}}; there are sometimes reasons to do this (e.g. a model that is defined
for tests only).
--
Ticket URL: <https://code.djangoproject.com/ticket/24686#comment:35>
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/0107018c9deddfa2-7da2876e-9b54-4d24-9c44-cff88a9e0d6d-000000%40eu-central-1.amazonses.com.