django redistributable app with south
Django apps that are meant to be redistributed don't have a manage.py (nor a settings.py since that is part of the project, not the app).
How does one run schemamigration --auto in this scenario? Do I need to have a minimal settings/manage.py as part of the app repository in order to do this? Is there a way to do this with django-admin.py?
You just need to add the app to your Installed_Apps
in your settings.py
Then you can run ./manage.py schemamigration <app_name> --auto
If the app doesn't have any migrations you will want to run ./manage.py schemamigration <app_name> --initial
first and then ./manage.py schemamigration <app_name> --auto
from then on.
Just managed to get this working in one of my project. Here's the code that works for me:
import sys
from django.conf import settings
from django.core.management import call_command
if not settings.configured:
settings.configure(
ROOT_URLCONF='',
DEBUG=False,
DATABASES={
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'test.db'
}
},
INSTALLED_APPS=(
'south',
'my_app',
)
)
if __name__ == "__main__":
call_command('schemamigration', 'my_app',
initial=len(sys.argv) > 1,
auto=len(sys.argv) == 0
The above script is saved as migrate.py
and run with python migrate.py
or python migrate.py i
(the i
can be anything, and it will use --initial
instead of --auto
if present). Obviously, you can do fancier command line option parsin, but this works for me.
EDIT: Updated the script, DATABASES
key was missing. On this project, I used the same database for testing the code, so it's not an entirely arbitrary configuration.
上一篇: Django的CSS和JS文件
下一篇: 与南部的Django可再发行的应用程序