[英]Django 1.7 migrations not being picked up
Using Django 1.7 and it's new migration I am running into a strange issue. 使用Django 1.7和它的新迁移我遇到了一个奇怪的问题。
I split my settings files up into 3 files which I have always done pre version 1.7 eg... 我将我的设置文件分成3个文件,我一直在1.7版之前完成,例如......
/settings
__init__.py
base.py
development.py
production.py
__init__.py __init__.py
from .base import *
if sys.argv[1] == 'runserver':
from .development import *
else:
from .production import *
Both development.py
and production.py
have there own database settings for there environment. development.py
和production.py
都有自己的环境数据库设置。 However with the new migrations system running migrations does not detect anything UNLESS I put the database settings in the base.py
files. 但是,运行迁移的新迁移系统无法检测到任何内容,除非我将数据库设置放在base.py
文件中。
Should I modifity this line to the following: 我应该将此行修改为以下内容:
if sys.argv[1] == 'runserver' or sys.argv[1] == 'migrate':
Or there a better way? 还是有更好的方法?
You should avoid adding logic to your settings file, consider using che --settings option when testing with runserver, like this: 您应该避免在设置文件中添加逻辑,在使用runserver进行测试时,请考虑使用che --settings选项,如下所示:
./manage.py --settings=project.settings.development runserver
You can also use environment variable DJANGO_SETTINGS_MODULE to switch the settings module used by Django. 您还可以使用环境变量DJANGO_SETTINGS_MODULE来切换Django使用的设置模块。
In your development enviroment you could set: 在您的开发环境中,您可以设置:
export DJANGO_SETTINGS_MODULE=project.settings.development
While in production you could set DJANGO_SETTINGS_MODULE=project.settings.production. 在制作中,您可以设置DJANGO_SETTINGS_MODULE = project.settings.production。
The details depend on the type of deployment and server you are using. 详细信息取决于您使用的部署类型和服务器。
Personally in my development setup I use virtualenv wrapper , and I set up the postactivate hook with something like this: 在我的开发设置中,我个人使用virtualenv包装器 ,并使用以下内容设置postactivate挂钩:
#!/bin/bash
# This hook is run after this virtualenv is activated.
export DJANGO_SETTINGS_MODULE=project.settings.local
cd /home/user/develop/git/project
In this way I can type 通过这种方式,我可以输入
workon project workon项目
And I have the environment variable correctly set, and my shell sent on the right folder. 我正确设置了环境变量,并在正确的文件夹中发送了我的shell。
You can have a base.py settings file with all your common settings, then in development.py (and production.py) you can do something like this: 您可以拥有一个包含所有常用设置的base.py设置文件,然后在development.py(和production.py)中,您可以执行以下操作:
from .base import *
DATABASES = ... customize DB settings used for development/production ...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.