Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change the order in which Django migrate app during testing

I am using the custom user model which inherits from the AbstractBaseUser class. When I try to migrate after makemigrations command

django.db.utils.ProgrammingError: relation "custom_user_users" does not exist

This is happening since Django is trying to migrate other apps first which depends upon the custom user model. Even I tried to changing the order of the app which contains the custom user model in INSTALLED_APP but no luck.

I know I can force fully migrate custom_user model first then let Django migrate all other models. This solves the problem but during running test it runs the migration in order which Django decides.

How can I alter the order in which apps are migrated during test ? Any other way to solve this dependency problem ?

I am using Django 1.8

like image 834
Jimit Avatar asked Apr 22 '15 13:04

Jimit


People also ask

How does Django know which migrations have run?

Django writes a record into the table django_migrations consisting of some information like the app the migration belongs to, the name of the migration, and the date it was applied.

How do I fix migration issues in Django?

you can either: temporarily remove your migration, execute python manage.py migrate, add again your migration and re-execute python manage.py migrate. Use this case if the migrations refer to different models and you want different migration files for each one of them.


2 Answers

Put your your apps before Django apps in INSTALLED_APP in settings.py file

like image 121
Vishal Mopari Avatar answered Sep 28 '22 03:09

Vishal Mopari


https://pypi.python.org/pypi/django-test-without-migrations adds a --nomigrations flag to manage.py test. Works like a charm.

like image 33
Robin van Leeuwen Avatar answered Sep 28 '22 03:09

Robin van Leeuwen