Migrations in stand alone Django app

后端 未结 2 1042
伪装坚强ぢ
伪装坚强ぢ 2021-01-13 14:06

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/intr

2条回答
  •  心在旅途
    2021-01-13 14:22

    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')
    

提交回复
热议问题