简体   繁体   English

在测试期间更改Django迁移应用的顺序

[英]Change the order in which Django migrate app during testing

I am using the custom user model which inherits from the AbstractBaseUser class. 我正在使用从AbstractBaseUser类继承的自定义用户模型。 When I try to migrate after makemigrations command 当我在makemigrations命令之后尝试迁移时

django.db.utils.ProgrammingError: relation "custom_user_users" does not exist django.db.utils.ProgrammingError:关系“ custom_user_users”不存在

This is happening since Django is trying to migrate other apps first which depends upon the custom user model. 之所以会这样,是因为Django首先尝试迁移其他应用程序,具体取决于自定义用户模型。 Even I tried to changing the order of the app which contains the custom user model in INSTALLED_APP but no luck. 甚至我都尝试更改INSTALLED_APP中包含自定义用户模型的应用程序的顺序,但是没有运气。

I know I can force fully migrate custom_user model first then let Django migrate all other models. 我知道我可以先强制完全迁移custom_user模型,然后让Django迁移所有其他模型。 This solves the problem but during running test it runs the migration in order which Django decides. 这解决了问题,但是在运行测试期间,它将按照Django决定的顺序运行迁移。

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 我正在使用Django 1.8

将您的应用放在settings.py文件中INSTALLED_APP中的Django应用之前

https://pypi.python.org/pypi/django-test-without-migrations adds a --nomigrations flag to manage.py test. https://pypi.python.org/pypi/django-test-without-migrations添加了--nomigrations标志来进行manage.py测试。 Works like a charm. 奇迹般有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM