Migrations in stand alone Django app

☆樱花仙子☆ 提交于 2019-12-19 09:27:29

问题


How do I makemigrations on a stand alone Django app (ie one that is not part if any project).

For example after following: https://docs.djangoproject.com/en/1.8/intro/reusable-apps/


回答1:


You can do it similar to how you do testing scripts for apps:

#!/usr/bin/env python

import sys
import django

from django.conf import settings
from django.core.management import call_command

settings.configure(DEBUG=True,
    INSTALLED_APPS=(
        'django.contrib.contenttypes',
        'your_app',
    ),
)

django.setup()
call_command('makemigrations', 'your_app')



回答2:


What I do is to create a mock project, containing only that app, then the process is as usual:

manage.py makemigrations myapp


来源:https://stackoverflow.com/questions/30656162/migrations-in-stand-alone-django-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!