what i'm trying to do is to change the default path for migrations for a specific application in a django project to put it outside the project itself but keeping it transparent, keeping use of makemigrations and migrate. Is it possible? if yes, how?
Asked
Active
Viewed 4,905 times
8
-
First of all, why do you want to put it outside ? – MD. Khairul Basar Sep 29 '17 at 09:52
-
yes, it MUST be outside for my purpose – Giuseppe Sep 29 '17 at 09:55
-
Explain *why*. Migrations are part of each app. – Daniel Roseman Sep 29 '17 at 10:10
-
during Continuous integration the old code will be deleted and the newone will be put in same path and a new migration will be run in case of models' modifies, so i need to keep mi migration files during my versioning – Giuseppe Sep 29 '17 at 10:16
1 Answers
12
Django has a MIGRATION_MODULES
setting. It allows you to specify a different module for migrations per app. The module can be outside of the Django project, it just needs to be on your python path.
MIGRATION_MODULES = {'myapp': 'othermodule.db_migrations'}

Alasdair
- 298,606
- 55
- 578
- 516
-
1This is pretty handy too for when you want to move the migrations folder into a subfolder of the django app, project>app>database>migrations for example. This way, you can bundle everything that is related to the database: models and migrations. – Sander Vanden Hautte Apr 18 '18 at 12:16
-
How can I specify location for installed independent django app?. I have an installed django app which has all the models and I want to generate migration files and put them under the django project I am using the app into. How can I achieve that? – Aditya Jun 28 '20 at 23:12
-
@aditya the above answer should work. `myapp` is your installed app, and `othermodule.db_migrations` is in your Django project. – Alasdair Jun 29 '20 at 07:56