我刚刚更新到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):
现在,这对我提出了3个问题。
如警告中所述,将发生以下两种情况:
INSTALLED_APPS
通常,当你有from .models import SomeModels一个apps.py早期信号时(例如post_migrate),就会发生这种情况。建议不要使用AppConfig.get_model()代替这里的经典方法。检查你的apps.py文件是否有任何模型导入,并使用此api替换它们。
from .models import SomeModels
post_migrate
例如代替:
# 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)
请注意,此强制性是在Bug #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
'django.contrib.sites'到INSTALLED_APPS