<tfoot id='1C1yI'></tfoot>

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

      <small id='1C1yI'></small><noframes id='1C1yI'>

      “没有安装带有‘admin’标签的应用程序"运行 Django 迁移.该应用程序已正确安装

      时间:2023-11-08
        <tbody id='niugH'></tbody>
        • <bdo id='niugH'></bdo><ul id='niugH'></ul>
          1. <i id='niugH'><tr id='niugH'><dt id='niugH'><q id='niugH'><span id='niugH'><b id='niugH'><form id='niugH'><ins id='niugH'></ins><ul id='niugH'></ul><sub id='niugH'></sub></form><legend id='niugH'></legend><bdo id='niugH'><pre id='niugH'><center id='niugH'></center></pre></bdo></b><th id='niugH'></th></span></q></dt></tr></i><div id='niugH'><tfoot id='niugH'></tfoot><dl id='niugH'><fieldset id='niugH'></fieldset></dl></div>
          2. <tfoot id='niugH'></tfoot>
              <legend id='niugH'><style id='niugH'><dir id='niugH'><q id='niugH'></q></dir></style></legend>

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

              1. 本文介绍了“没有安装带有‘admin’标签的应用程序"运行 Django 迁移.该应用程序已正确安装的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在尝试在 Django 1.7 上进行数据迁移期间使用 admin.LogEntry 对象

                I am trying to use admin.LogEntry objects during a datamigration on Django 1.7

                'django.contrib.admin' 应用程序列在 INSTALLED_APPS 上.

                The 'django.contrib.admin' app is listed on INSTALLED_APPS.

                在外壳上,它可以工作:

                On the shell, it works:

                >>> from django.apps import apps
                >>> apps.get_model('admin', 'LogEntry')
                django.contrib.admin.models.LogEntry
                

                但是在迁移过程中,它失败了:

                But during the migration, it fails:

                def do_it(apps, schema_editor):
                    LogEntry = apps.get_model('admin', 'LogEntry')
                

                这样失败:

                django-admin migrate
                (...)
                LookupError: No installed app with label 'admin'.
                

                使用调试器,我发现管理员"没有安装:

                Using a debugger, I got that the 'admin' is not installed:

                ipdb> apps.get_apps()
                []
                ipdb> apps.all_models.keys()
                ['website', 'google', 'allauth', 'twitter', 'busca', 'conteudo', 'django_mobile', 'django_filters', 'videocenter', 'tinymce', 'oferta', 'programacaotv', 'contenttypes', 'suit', 'haystack', 'destaque', 'filer', 'galeria', 'auth', 'facebook', 'paintstore', 'critica', 'disqus', 'fichas', 'omeletop', 'autocomplete_light', 'modelsv1', 'temas', 'django_extensions', 'adv_cache_tag', 'taggit', 'social', 'personalidade']
                

                为什么??

                推荐答案

                Django doc 说得很清楚:

                当编写一个 RunPython 函数使用来自迁移所在应用之外的其他应用的模型时,迁移的 dependencies 属性应包含每个应用的最新迁移,否则当您尝试使用 RunPython 函数检索模型时,您可能会收到类似于:LookupError: No installed app with label 'myappname'strong>apps.get_model().

                When writing a RunPython function that uses models from apps other than the one in which the migration is located, the migration’s dependencies attribute should include the latest migration of each app that is involved, otherwise you may get an error similar to: LookupError: No installed app with label 'myappname' when you try to retrieve the model in the RunPython function using apps.get_model().

                代码示例:

                # Imports are omitted for the sake of brevity
                
                def move_m1(apps, schema_editor):
                    LogEntry = apps.get('admin.logentry')
                    # Other business logic here ...
                
                
                class Migration(migrations.Migration):
                
                    dependencies = [
                        ('app1', '0001_initial'),
                
                        # Below is the manually added dependency, so as to retrieve models
                        # of 'django.contrib.admin' app with apps.get_model() in move_m1().
                        #
                        # Currently this is for Django 1.11. You need to look into
                        # 'django/contrib/admin/migrations' directory to find out which is
                        # the latest migration for other version of Django.
                        ('admin', '0002_logentry_remove_auto_add'),
                    ]
                
                    operations = [
                        migrations.RunPython(move_m1),
                    ]
                

                这篇关于“没有安装带有‘admin’标签的应用程序"运行 Django 迁移.该应用程序已正确安装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:允许"-&quot;Django 管理界面中用户名中的字符 下一篇:如何抑制 Django 中的弃用警告?

                相关文章

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

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

              3. <legend id='cIvVr'><style id='cIvVr'><dir id='cIvVr'><q id='cIvVr'></q></dir></style></legend>

              4. <tfoot id='cIvVr'></tfoot>