Opened 4 years ago

Closed 4 years ago

#25288 closed New feature (needsinfo)

Allow migrating models from other apps

Reported by: Emmanuelle Delescolle Owned by: nobody
Component: Migrations Version: 1.8
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Although this might be dangerous, this is not the first time I come across the need for migrating models from other apps.

One simple use case is when using modeltranslations, even if you create a translation.py in your own application to add multi-lingual capabilities to models from other apps, when running manage.py makemigations the migrations will be created in the original app's directory. Therefore, when deploying the project on another machine, the migrations will not be available (as the original app will probably be deployed from pypi) and the whole project will crash.

Using MIGRATION_MODULES is not a suitable solutions as we still want to use the original app's other migrations.

(This is not the only use case, but it's probably one of the most frequent ones)

A quite easy solution is to add (maybe with a warning) a "migrated_app" parameter to the Migration class. If this parameter is not None it will be used to determine the application the migration has to be applied to. If it is None, normal behavior is resumed with the app to which that migration belongs to.

With this feature, manage.py makemigrations would still generate the migrations in the original app's directory, then the user would need to move and rename those newly generated files to their own application (with appropriate dependencies). This isn't more complicated than creating a data migration.

You can find an implementation of this feature here: http://stackoverflow.com/questions/24311993/how-to-add-a-new-field-to-a-model-with-new-django-migrations/27450550#27450550

If this is triaged and accepted I'll create appropriate PR for the code with some tests and documentation

Change History (2)

comment:1 Changed 4 years ago by Tim Graham

I'd suggest to write to the DevelopersMailingList to get feedback on the idea.

comment:2 Changed 4 years ago by Tim Graham

Has patch: unset
Resolution: needsinfo
Status: newclosed
Note: See TracTickets for help on using tickets.
Back to Top