Python “未安装带有标签‘admin’的应用”正在运行 Django 迁移。该应用程序已正确安装
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29565665/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
"No installed app with label 'admin'" running Django migration. The app is installed correctly
提问by alanjds
I am trying to use admin.LogEntry objects during a datamigration on Django 1.7
我正在尝试在 Django 1.7 上的数据迁移期间使用 admin.LogEntry 对象
The 'django.contrib.admin'
app is listed on INSTALLED_APPS
.
该'django.contrib.admin'
应用程序列在 上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')
Fails like this:
失败是这样的:
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']
WHY??
为什么??
采纳答案by Rockallite
The Django docmakes it clear:
在Django的文档清楚:
When writing a RunPythonfunction that uses models from apps other than the one in which the migration is located, the migration's dependenciesattribute 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 RunPythonfunction using apps.get_model().
在编写使用来自应用程序而非迁移所在应用程序的模型的RunPython函数时,迁移的依赖项属性应包含所涉及的每个应用程序的最新迁移,否则您可能会收到类似于以下内容的错误:LookupError: No installed当您尝试使用apps.get_model()在RunPython函数中检索模型时,您会看到带有标签“myappname”的app。
Code example:
代码示例:
# 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),
]
回答by JV.
I don't know the exact cause for this. Will have to dig into the source code. but for now a workaround is add
('admin', 'name_of_last_migration_in_admin_app')
to the dependencies and the migrations shall go alright.
我不知道造成这种情况的确切原因。将不得不深入研究源代码。但是现在一个解决方法是添加
('admin', 'name_of_last_migration_in_admin_app')
到依赖项中,迁移会顺利进行。
回答by Sibin John Mattappallil
I got the same error (but unrelated to the issue mentioned in question). I was using mysql db but there were no mysql client.
我遇到了同样的错误(但与所提到的问题无关)。我使用的是 mysql db,但没有 mysql 客户端。
settings.py
设置.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
# other details like name, user, host
}
}
I installed mysqlclient (In ubuntu & Python3):
我安装了 mysqlclient(在 ubuntu 和 Python3 中):
sudo apt-get install libmysqlclient-dev
sudo apt-get install python3-dev
pip install mysqlclient
回答by Colton Hicks
Try looking further up your stack trace too. I got this error due to a misconfigured logger but I had to look further up the trace to find this issue!
尝试进一步查找您的堆栈跟踪。由于记录器配置错误,我收到此错误,但我必须进一步查找跟踪才能找到此问题!
In my case I had misnamed my environment variable DJANGO_LOG_LEVL
as DEGUB
instead of DEBUG
(note the misspelling) and that caused the error.
在我来说,我已经名不副实我的环境变量DJANGO_LOG_LEVL
作为DEGUB
代替DEBUG
(注意拼写错误),并导致错误。
回答by Rohan Gaikwad
I was getting a similar error and I am a total novice programmer. One solution that worked for me was installing sqlparse. Try
我遇到了类似的错误,我是一个完全的新手程序员。对我有用的一种解决方案是安装 sqlparse。尝试
pip install sqlparse
pip 安装 sqlparse
回答by user11581168
I also had this same error of "no installed app label 'admin' ". I was able to solve it by running the pip install sqlparse command
我也有同样的错误“没有安装的应用程序标签‘admin’”。我能够通过运行 pip install sqlparse 命令来解决它
回答by Yuvaraj K
For me it shows
对我来说它显示
raise LookupError(message)
LookupError: No installed app with label 'admin'.
LookupError: 未安装带有标签“admin”的应用程序。
and I solve it by pip installing every requirements manually I m using ubuntu 16.04
我通过 pip 手动安装每个要求来解决它我使用的是 ubuntu 16.04
回答by steve serria
For my case the LookupError was occuring because I had altered the models and added 'related_name' but had not run makemigrations and migrate.
对于我的情况,发生 LookupError 是因为我更改了模型并添加了“related_name”,但没有运行 makemigrations 和 migrate。
回答by folorunso joseph
I got the error when I used 'required=False' in my model like this: slug = models.SlugField(required=False)
当我在模型中使用 'required=False' 时出现错误,如下所示:slug = models.SlugField(required=False)
I changed it to: slug = models.SlugField(blank=True,null=True) and the error disappeared
我将其更改为: slug = models.SlugField(blank=True,null=True) 并且错误消失了