Django 1.9 지원 중단 경고 app_label
방금 Django v1.8로 업데이트하고 프로젝트를 업데이트하기 전에 로컬 설정을 테스트했으며 이전에 본 적이없는 사용 중단 경고를 받았으며 나에게 의미가 없습니다. 나는 단지 무언가를 간과하거나 문서를 오해하고있을 수 있습니다.
/Users/neilhickman/Sites/guild/ankylosguild/apps/raiding/models.py:6: RemovedInDjango19Warning: Model class ankylosguild.apps.raiding.models.Difficulty doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS or else was imported before its application was loaded. This will no longer be supported in Django 1.9.
class Difficulty(models.Model):
/Users/neilhickman/Sites/guild/ankylosguild/apps/raiding/models.py:21: RemovedInDjango19Warning: Model class ankylosguild.apps.raiding.models.Zone doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS or else was imported before its application was loaded. This will no longer be supported in Django 1.9.
class Zone(models.Model):
/Users/neilhickman/Sites/guild/ankylosguild/apps/raiding/models.py:49: RemovedInDjango19Warning: Model class ankylosguild.apps.raiding.models.Boss doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS or else was imported before its application was loaded. This will no longer be supported in Django 1.9.
class Boss(models.Model):
/Users/neilhickman/Sites/guild/ankylosguild/apps/raiding/models.py:79: RemovedInDjango19Warning: Model class ankylosguild.apps.raiding.models.Item doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS or else was imported before its application was loaded. This will no longer be supported in Django 1.9.
class Item(models.Model):
/Users/neilhickman/Sites/guild/ankylosguild/apps/forum/models.py:14: RemovedInDjango19Warning: Model class ankylosguild.apps.forum.models.Category doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS or else was imported before its application was loaded. This will no longer be supported in Django 1.9.
class Category(models.Model):
/Users/neilhickman/Sites/guild/ankylosguild/apps/forum/models.py:36: RemovedInDjango19Warning: Model class ankylosguild.apps.forum.models.Comment doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS or else was imported before its application was loaded. This will no longer be supported in Django 1.9.
class Comment(ScoreMixin, ProfileMixin, models.Model):
/Users/neilhickman/Sites/guild/ankylosguild/apps/forum/models.py:64: RemovedInDjango19Warning: Model class ankylosguild.apps.forum.models.Forum doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS or else was imported before its application was loaded. This will no longer be supported in Django 1.9.
class Forum(models.Model):
/Users/neilhickman/Sites/guild/ankylosguild/apps/forum/models.py:88: RemovedInDjango19Warning: Model class ankylosguild.apps.forum.models.Post doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS or else was imported before its application was loaded. This will no longer be supported in Django 1.9.
class Post(ScoreMixin, ProfileMixin, models.Model):
/Users/neilhickman/Sites/guild/ankylosguild/apps/forum/models.py:119: RemovedInDjango19Warning: Model class ankylosguild.apps.forum.models.CommentPoint doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS or else was imported before its application was loaded. This will no longer be supported in Django 1.9.
class CommentPoint(models.Model):
/Users/neilhickman/Sites/guild/ankylosguild/apps/forum/models.py:127: RemovedInDjango19Warning: Model class ankylosguild.apps.forum.models.TopicPoint doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS or else was imported before its application was loaded. This will no longer be supported in Django 1.9.
class TopicPoint(models.Model):
/Users/neilhickman/Sites/guild/ankylosguild/apps/auctionhouse/models.py:10: RemovedInDjango19Warning: Model class ankylosguild.apps.auctionhouse.models.Auction doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS or else was imported before its application was loaded. This will no longer be supported in Django 1.9.
class Auction(models.Model):
/Users/neilhickman/Sites/guild/ankylosguild/apps/auctionhouse/models.py:83: RemovedInDjango19Warning: Model class ankylosguild.apps.auctionhouse.models.Bid doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS or else was imported before its application was loaded. This will no longer be supported in Django 1.9.
class Bid(models.Model):
이제 이것은 나에게 세 가지 질문을 제기합니다.
- 에 따르면 문서 ,
Options.app_label
모델 내 경우, 그렇지 않은 응용 프로그램 모듈의 외부하지 않는 한 요구 사항은 아닙니다. 둘째,이 동작은 어쨌든 1.7에서 더 이상 사용되지 않았는데 왜 문제가 될까요? - 응용 프로그램은 모두 INSTALLED_APPS 튜플에 있으므로 확실히 그럴 수 없습니까?
- 모든 것이 INSTALLED_APPS 튜플에있는 경우 응용 프로그램이 호출되기 전에로드되지 않는 이유는 무엇입니까?
내가 실제로 뭔가 잘못하고 있다면 문서 가이 문제를 일으키는 원인이나 수정 방법을 실제로 명확하게 밝히지 않으므로 올바른 방법은 무엇입니까?
경고에 명시된대로 다음 중 하나가 발생합니다.
- 에없는 모델을 사용하는 경우
INSTALLED_APPS
; - 또는 애플리케이션이로드되기 전에 모델을 사용하는 경우.
INSTALLED_APPS
설정 에서 앱을 참조 했으므로 앱 초기화 전에 모델을 사용하고있을 가능성이 큽니다.
일반적으로 from .models import SomeModels
이는 apps.py 초기 신호 (예 :) 에 있을 때 발생합니다 post_migrate
. 여기서 고전적인 방식으로 모델을 참조하는 대신 AppConfig.get_model () 을 사용하는 것이 좋습니다 . 모든 모델 가져 오기에 대한 apps.py 파일을 확인 하고이 API를 사용하여 대체하십시오.
예를 들면 다음과 같습니다.
# apps.py
from django.apps import AppConfig
from .models import MyModel
def do_stuff(sender, **kwargs):
MyModel.objects.get() # etc...
class MyAppConfig(AppConfig):
name = 'src.my_app_label'
def ready(self):
post_migrate.connect(do_stuff, sender=self)
이 작업을 수행 :
# apps.py
from django.apps import AppConfig
def do_stuff(sender, **kwargs):
mymodel = sender.get_model('MyModel')
mymodel.objects.get() # etc...
class MyAppConfig(AppConfig):
name = 'src.my_app_label'
def ready(self):
post_migrate.connect(do_stuff, sender=self)
이 시행은 버그 # 21719 에서 도입되었습니다 .
비슷한 오류입니다. 제 경우에는 오류가 다음과 같습니다.
RemovedInDjango19Warning: Model class django.contrib.sites.models.Site doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS or else was imported before its application was loaded. This will no longer be supported in Django 1.9.
class Site(models.Model):
내 솔루션은 다음과 같습니다.
추가 'django.contrib.sites'
로INSTALLED_APPS
나는이 오류를 보는 사람들 중 소수만이 나와 같은 일로 인해 발생할 것이라고 생각하지만 다른 사람에게 도움이되는 경우이 답변을 추가 할 가치가있는 것 같습니다!
한 지점에서 테스트를 실행할 때 갑자기 이러한 오류가 많이 보였습니다 __init__.py
. 하위 디렉터리에있을 예정일 때 장고 프로젝트의 최상위 수준에서 실수로 파일을 만든 것으로 나타났습니다 . 이것이 발생했다는 단서는 다음과 같은 오류입니다.
/home/mark/mystupiddjangoproject/alerts/models.py:15: RemovedInDjango19Warning: Model class mystupiddjangoproject.alerts.models.Alert doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS or else was imported before its application was loaded. This will no longer be supported in Django 1.9.
class Alert(models.Model):
... mystupiddjangoproject
정규화 된 모델 이름에 프로젝트가있는 디렉토리 이름 ( )이 포함되어 있어야합니다 alerts.models.Alert
.
이 문제를 해결하려면 다음을 수행해야합니다.
rm __init__.py
rm __init__.pyc
비슷한 오류가 발생했지만 앱의 모델에 대해 불평하는 대신 contrib
패키지의 모델에 대해 불평했습니다 . 예를 들면 :
C : \ Program Files \ Python 2.7 \ lib \ site-packages \ django \ contrib \ sessions \ models.py : 27 : RemovedInDjango19Warning : 모델 클래스 django.contrib.sessions.models.Session은 명시적인 app_label을 선언하지 않으며 둘 중 하나가 아닙니다. INSTALLED_APPS의 응용 프로그램에 있지 않거나 응용 프로그램이로드되기 전에 가져 왔습니다. 이는 Django 1.9에서 더 이상 지원되지 않습니다. class Session (models.Model) :
이는에서 INSTALLED_APPS
속성 의 잘못된 순서로 인해 발생합니다 settings.py
. 내 settings.py
처음에는
INSTALLED_APPS = (
'my_app_1',
'my_app_2',
'my_app_3',
'bootstrap_admin',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.messages',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.staticfiles',
'social.apps.django_app.default',
'mathfilters',
'rest_framework',
)
my_app_*
contrib
패키지의 모델을 사용 하십시오. 이 오류는 모델을 선언하기 전에 모델을 사용하여 발생합니다 (즉 Django
, 모델 을 사용 하기 전에 해당 모델을 포함하는 앱에 대해 알아야 함 ).
이를 해결하기 위해서는 앱이 선언되는 순서를 변경해야합니다. 특히 모든 Django 앱은 사용자 정의 앱보다 먼저 나와야합니다 . 제 경우에는 올바른 INSTALLED_APPS
것 같습니다.
INSTALLED_APPS = (
'bootstrap_admin',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.messages',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.staticfiles',
'social.apps.django_app.default',
'mathfilters',
'rest_framework',
'my_app_1',
'my_app_2',
'my_app_3',
)
이제 이것이 귀하의 질문에 직접 답변하지 않을 수도 있지만 관련 질문에 대한 답변이며 오류를 붙여 넣을 때 Google에 표시되는 유일한 SO 링크이므로 여기에 답변했습니다.
그러나 비슷한 상황이 문제의 원인이라고 생각합니다.
Make sure you declare the "dependency" apps before the apps using them! The errors don't really specify which app is using a model, so you would have to push the app containing the model it mentions to the top, one by one, until the error disappears.
Add a meta class to your model with an app_label attribute.
class Meta:
app_label = 'app_model_belongs_to'
Hope this works!
EDIT: The reason for this is usually that the model exists outside of the standard locations.
For more information refer to: https://docs.djangoproject.com/en/1.8/ref/models/options/#app-label
I faced this issue as well and it was related to the way I was loading the signals.py module from an app.
As you may now, it's quite common to have circular import issues between the signals and the models, and it's usual to import them from the app's __init__.py
file or from the bottom of the models.py
file to avoid them.
Well, I was using the __init__.py
approach, and just moving the import signals
statement to the bottom of my models.py
file solved the issue.
Hope this helps someone else!
I has this problem after upgrade Django from 1.8 to 1.9.1:
RuntimeError at /
Model class blog.models.BlogCategory doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.
This help to resolve:
in blog/models.py:
class BlogCategory(models.Model):
some vars & methods
class Meta:
app_label = 'BlogCategory'
It's work on 100%.
I had the same problem. I put a breakpoint in django.db.models.base.py:line82 and try to figure out what is causing this warning message.
# Look for an application configuration to attach the model to.
app_config = apps.get_containing_app_config(module)
Basically, if your app does not exist by this time, you get that warning. I realized that my problem was that I have a third party framework (in my case, haystack) that tries to import one of my custom models.
Maybe you also have a third party package listed in INSTALLED_APPS before your custom apps and your third party package references your custom apps? This would be possible if you are using something like Django rest framework as well.
The Django 1.9 way of handling this and giving your app a nice name in the admin is to do the following:
Add a file in your app named apps.py
and add the following to it:
#apps.py
from django.apps import AppConfig
class YourAppNameAppConfig(AppConfig):
name = 'yourappname'
verbose_name = 'Your App Name Looking Right'
Then, in your app's __init__.py
file, add the following:
#__init__.py
default_app_config = 'youappname.apps.YourAppNameAppConfig'
Sometimes an invalid .pyc files that doesnt match with the current source code caused this problem.
I removed all .pyc to refresh all of them using this bash
find . -name "*.pyc" -exec rm -rf {} \;
The easiest and simplest way to solve this is to place the "import signals" command at the BOTTOM of the Model file you are working with. This ensures that the models are all loaded before the signals for that model are imported. You would have to do this for each model you are importing (if you use receivers linked to particular models), or in the models.py for the app that comes at the end of the "installed apps" in your settings.
The other solutions are only required if you are dealing with non-model type signals, where the models will never be imported first.
Why this is not noted in the docs is a mystery, because I just got caught by it, until I remembered that you have to do that.
models.py
from django.db import models
class MyModel(models.Model):
myfield1 = models.CharField()
myfield2 = models.CharField()
import signals
And then in signals.py:
from django.db.models.signals import pre_save # Or whatever you are using
from django.dispatch import receiver
from .models import MyModel
@receiver(pre_save, sender=MyModel)
def my_receiver(sender, instance, **kwargs):
mysender = sender
print mysender
Like that.
I didn't receive any error in django 1.7. While migrating to django 1.8 I got this error. Reason was the signal were defined in app/signal_receiver.py
.
I created a apps.py
from django.apps import AppConfig
class TasksConfig(AppConfig):
name = 'core'
verbose_name = "core"
def ready(self):
import core.signal.handler
I moved signal receiver in handler.py
inside signal package.
참고URL : https://stackoverflow.com/questions/29635765/django-1-9-deprecation-warnings-app-label
'Nice programing' 카테고리의 다른 글
포트에 바인딩 할 때 SSL 인증서 추가에 실패했습니다. (0) | 2020.12.06 |
---|---|
Laravel : DB :: transaction ()과 함께 try… catch 사용 (0) | 2020.12.06 |
string 형 벡터를 할당하여 열 이름으로 빈 데이터 프레임을 만드시겠습니까? (0) | 2020.12.06 |
.NET 소스 코드 디버깅을위한 .cs 파일을 찾을 수 없습니다. (0) | 2020.12.06 |
더 빠른 작업, re.match / search 또는 str.find는 무엇입니까? (0) | 2020.12.06 |