<small id='yqnef'></small><noframes id='yqnef'>

  1. <i id='yqnef'><tr id='yqnef'><dt id='yqnef'><q id='yqnef'><span id='yqnef'><b id='yqnef'><form id='yqnef'><ins id='yqnef'></ins><ul id='yqnef'></ul><sub id='yqnef'></sub></form><legend id='yqnef'></legend><bdo id='yqnef'><pre id='yqnef'><center id='yqnef'></center></pre></bdo></b><th id='yqnef'></th></span></q></dt></tr></i><div id='yqnef'><tfoot id='yqnef'></tfoot><dl id='yqnef'><fieldset id='yqnef'></fieldset></dl></div>

      <legend id='yqnef'><style id='yqnef'><dir id='yqnef'><q id='yqnef'></q></dir></style></legend>

        <bdo id='yqnef'></bdo><ul id='yqnef'></ul>
      <tfoot id='yqnef'></tfoot>
    1. 如何为可重用的 Django 应用程序进行迁移?

      How to make migrations for a reusable Django app?(如何为可重用的 Django 应用程序进行迁移?)
    2. <small id='Nra2R'></small><noframes id='Nra2R'>

          • <bdo id='Nra2R'></bdo><ul id='Nra2R'></ul>

                <tfoot id='Nra2R'></tfoot>
                <i id='Nra2R'><tr id='Nra2R'><dt id='Nra2R'><q id='Nra2R'><span id='Nra2R'><b id='Nra2R'><form id='Nra2R'><ins id='Nra2R'></ins><ul id='Nra2R'></ul><sub id='Nra2R'></sub></form><legend id='Nra2R'></legend><bdo id='Nra2R'><pre id='Nra2R'><center id='Nra2R'></center></pre></bdo></b><th id='Nra2R'></th></span></q></dt></tr></i><div id='Nra2R'><tfoot id='Nra2R'></tfoot><dl id='Nra2R'><fieldset id='Nra2R'></fieldset></dl></div>
                <legend id='Nra2R'><style id='Nra2R'><dir id='Nra2R'><q id='Nra2R'></q></dir></style></legend>
                  <tbody id='Nra2R'></tbody>
              1. 本文介绍了如何为可重用的 Django 应用程序进行迁移?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在制作一个没有项目的可重用 Django 应用程序.这是目录结构:

                I am making a reusable Django app without a project. This is the directory structure:

                /
                /myapp/
                /myapp/models.py
                /myapp/migrations/
                /myapp/migrations/__init__.py
                

                当我运行 django-admin makemigrations 时出现以下错误:

                When I run django-admin makemigrations I get the following error:

                django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
                

                显然,这是因为我没有配置设置模块,因为这是一个可重复使用的应用程序.但是,我仍然想使用我的应用程序进行迁移.我怎样才能制作它们?

                Obviously, this is because I don't have a settings module configured, because this is a reusable app. However, I would still like to ship migrations with my app. How can I make them?

                推荐答案

                其实你不需要有项目,你只需要设置文件和脚本,运行迁移创建.设置必须包含以下内容(最少):

                Actually, you don't need to have project, all you need is settings file and script, that runs migrations creation. Settings must contain folowing (minimum):

                # test_settings.py
                
                DEBUG = True
                
                SECRET_KEY = 'fake-key'
                
                INSTALLED_APPS = [
                    'django.contrib.admin',
                    'django.contrib.auth',
                    'django.contrib.contenttypes',
                    'your_app'
                ]
                

                进行迁移的脚本应该如下所示:

                And the script, that makes migrations should look like this:

                # make_migrations.py
                
                import os
                import sys
                
                if __name__ == "__main__":
                    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "test_settings")
                    from django.core.management import execute_from_command_line
                    args = sys.argv + ["makemigrations", "your_app"]
                    execute_from_command_line(args)
                

                你应该通过 python make_migrations.py 运行它.希望它可以帮助某人!

                and you should run it by python make_migrations.py. Hope it helps someone!

                这篇关于如何为可重用的 Django 应用程序进行迁移?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Running .jl file from R or Python(从 R 或 Python 运行 .jl 文件)
                Running Julia .jl file in python(在 python 中运行 Julia .jl 文件)
                Using PIP in a Azure WebApp(在 Azure WebApp 中使用 PIP)
                How to run python3.7 based flask web api on azure(如何在 azure 上运行基于 python3.7 的烧瓶 web api)
                Azure Python Web App Internal Server Error(Azure Python Web 应用程序内部服务器错误)
                Run python dlib library on azure app service(在 azure app 服务上运行 python dlib 库)
                <i id='YBB3g'><tr id='YBB3g'><dt id='YBB3g'><q id='YBB3g'><span id='YBB3g'><b id='YBB3g'><form id='YBB3g'><ins id='YBB3g'></ins><ul id='YBB3g'></ul><sub id='YBB3g'></sub></form><legend id='YBB3g'></legend><bdo id='YBB3g'><pre id='YBB3g'><center id='YBB3g'></center></pre></bdo></b><th id='YBB3g'></th></span></q></dt></tr></i><div id='YBB3g'><tfoot id='YBB3g'></tfoot><dl id='YBB3g'><fieldset id='YBB3g'></fieldset></dl></div>
                    <bdo id='YBB3g'></bdo><ul id='YBB3g'></ul>

                    <small id='YBB3g'></small><noframes id='YBB3g'>

                      <tbody id='YBB3g'></tbody>

                        1. <tfoot id='YBB3g'></tfoot>

                          <legend id='YBB3g'><style id='YBB3g'><dir id='YBB3g'><q id='YBB3g'></q></dir></style></legend>