从Django 1.5.5升级到Django 1.8.5

时间:2015-11-09 16:14:34

标签: python django

我必须使用Django 1.8.5,因为1.5.5的支持已经在webfaction上结束了,1.4.22不会起作用。这是我现在使用1.8.5的错误日志

[Mon Nov 09 19:03:25 2015] [error] [client 127.0.0.1] mod_wsgi (pid=963728): Exception occurred processing WSGI script '/home/kbuzz/webapps/django/kb/kb/wsgi.py'.
[Mon Nov 09 19:03:25 2015] [error] [client 127.0.0.1] Traceback (most recent call last):
[Mon Nov 09 19:03:25 2015] [error] [client 127.0.0.1]   File "/home/kbuzz/lib/python2.7/django/core/handlers/wsgi.py", line 170, in __call__
[Mon Nov 09 19:03:25 2015] [error] [client 127.0.0.1]     self.load_middleware()
[Mon Nov 09 19:03:25 2015] [error] [client 127.0.0.1]   File "/home/kbuzz/lib/python2.7/django/core/handlers/base.py", line 52, in load_middleware
[Mon Nov 09 19:03:25 2015] [error] [client 127.0.0.1]     mw_instance = mw_class()
[Mon Nov 09 19:03:25 2015] [error] [client 127.0.0.1]   File "/home/kbuzz/lib/python2.7/django/contrib/redirects/middleware.py", line 18, in __init__
[Mon Nov 09 19:03:25 2015] [error] [client 127.0.0.1]     if not apps.is_installed('django.contrib.sites'):
[Mon Nov 09 19:03:25 2015] [error] [client 127.0.0.1]   File "/home/kbuzz/lib/python2.7/django/apps/registry.py", line 231, in is_installed
[Mon Nov 09 19:03:25 2015] [error] [client 127.0.0.1]     self.check_apps_ready()
[Mon Nov 09 19:03:25 2015] [error] [client 127.0.0.1]   File "/home/kbuzz/lib/python2.7/django/apps/registry.py", line 124, in check_apps_ready
[Mon Nov 09 19:03:25 2015] [error] [client 127.0.0.1]     raise AppRegistryNotReady("Apps aren't loaded yet.")
[Mon Nov 09 19:03:25 2015] [error] [client 127.0.0.1] AppRegistryNotReady: Apps aren't loaded yet.

可能需要编辑wsgi才能使用django 1.8.5

"""
WSGI config for kb project.

This module contains the WSGI application used by Django's development server
and any production WSGI deployments. It should expose a module-level variable
named ``application``. Django's ``runserver`` and ``runfcgi`` commands discover
this application via the ``WSGI_APPLICATION`` setting.

Usually you will have the standard Django WSGI application here, but it also
might make sense to replace the whole Django WSGI application with a custom one
that later delegates to the Django one. For example, you could introduce WSGI
middleware here, or combine a Django application with an application of another
framework.

"""

import os
import sys

# http://generics7.blogspot.com/2014/06/setup-new-relic-with-webfaction-django.html

#os.environ.setdefault("DJANGO_SETTINGS_MODULE", "kb.settings")

# This application object is used by any WSGI server configured to use this
# file. This includes Django's development server, if the WSGI_APPLICATION
# setting points here.
#from django.core.wsgi import get_wsgi_application
#application = get_wsgi_application()
from django.core.handlers.wsgi import WSGIHandler

os.environ['DJANGO_SETTINGS_MODULE'] = 'kb.settings'
application = WSGIHandler()

# Apply WSGI middleware here.
# from helloworld.wsgi import HelloWorldApplication
# application = HelloWorldApplication(application)

如果它解决了问题,我会全部升级,但如果不解决则不行。当我尝试使用1.4.22时出现此错误

Environment:


Request Method: GET
Request URL: http://www.kenyabuzz.com/?device=browser

Django Version: 1.4.22
Python Version: 2.7.9
Installed Applications:
('django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.sitemaps',
 'django.contrib.messages',
 'django.contrib.markup',
 'django.contrib.staticfiles',
 'django.contrib.admin',
 'django.contrib.redirects',
 'django.contrib.humanize',
 'autocomplete_light',
 'memcache_status',
 'djangorestframework',
 'haystack',
 'lamusoftware.generic',
 'mptt',
 'bootstrapform',
 'sorl.thumbnail',
 'south',
 'oauth2client',
 'articles',
 'banners',
 'common',
 'directory',
 'events',
 'galleries',
 'marketplace',
 'movies',
 'pages',
 'profiles',
 'search',
 'stats',
 'minidetector',
 'mobile',
 'reports',
 'favorites',
 'braces',
 'allauth',
 'allauth.account',
 'allauth.socialaccount',
 'allauth.socialaccount.providers.facebook',
 'widget_tweaks',
 'wordofmouth',
 'ckeditor',
 'django_mobile',
 'debug_toolbar')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.contrib.redirects.middleware.RedirectFallbackMiddleware',
 'minidetector.Middleware',
 'mobileesp.middleware.MobileDetectionMiddleware',
 'kb.middleware.log_ip_middleware.SetRemoteAddrFromForwardedFor',
 'kb.middleware.log_ip_middleware.RedirectMovie')


Traceback:
File "/home/kbuzz/webapps/django/lib/python2.7/django/core/handlers/base.py" in get_response
  87.                     response = middleware_method(request)
File "/home/kbuzz/webapps/django/kb/kb/middleware/log_ip_middleware.py" in process_request
  65.         if request.user.is_authenticated():
File "/home/kbuzz/webapps/django/lib/python2.7/django/utils/functional.py" in inner
  184.             self._setup()
File "/home/kbuzz/webapps/django/lib/python2.7/django/utils/functional.py" in _setup
  248.         self._wrapped = self._setupfunc()
File "/home/kbuzz/webapps/django/lib/python2.7/django/contrib/auth/middleware.py" in <lambda>
  17.         request.user = SimpleLazyObject(lambda: get_user(request))
File "/home/kbuzz/webapps/django/lib/python2.7/django/contrib/auth/middleware.py" in get_user
  9.         request._cached_user = auth.get_user(request)
File "/home/kbuzz/webapps/django/lib/python2.7/django/contrib/auth/__init__.py" in get_user
  98.         user_id = request.session[SESSION_KEY]
File "/home/kbuzz/webapps/django/lib/python2.7/django/contrib/sessions/backends/base.py" in __getitem__
  39.         return self._session[key]
File "/home/kbuzz/webapps/django/lib/python2.7/django/contrib/sessions/backends/base.py" in _get_session
  172.                 self._session_cache = self.load()
File "/home/kbuzz/webapps/django/lib/python2.7/django/contrib/sessions/backends/db.py" in load
  19.                 expire_date__gt=timezone.now()
File "/home/kbuzz/webapps/django/lib/python2.7/django/db/models/manager.py" in get
  131.         return self.get_query_set().get(*args, **kwargs)
File "/home/kbuzz/webapps/django/lib/python2.7/django/db/models/query.py" in get
  358.         clone = self.filter(*args, **kwargs)
File "/home/kbuzz/webapps/django/lib/python2.7/django/db/models/query.py" in filter
  624.         return self._filter_or_exclude(False, *args, **kwargs)
File "/home/kbuzz/webapps/django/lib/python2.7/django/db/models/query.py" in _filter_or_exclude
  642.             clone.query.add_q(Q(*args, **kwargs))
File "/home/kbuzz/webapps/django/lib/python2.7/django/db/models/sql/query.py" in add_q
  1250.                             can_reuse=used_aliases, force_having=force_having)
File "/home/kbuzz/webapps/django/lib/python2.7/django/db/models/sql/query.py" in add_filter
  1122.                     process_extras=process_extras)
File "/home/kbuzz/webapps/django/lib/python2.7/django/db/models/sql/query.py" in setup_joins
  1304.                 field, model, direct, m2m = opts.get_field_by_name(name)
File "/home/kbuzz/webapps/django/lib/python2.7/django/db/models/options.py" in get_field_by_name
  311.                 cache = self.init_name_map()
File "/home/kbuzz/webapps/django/lib/python2.7/django/db/models/options.py" in init_name_map
  341.         for f, model in self.get_all_related_m2m_objects_with_model():
File "/home/kbuzz/webapps/django/lib/python2.7/django/db/models/options.py" in get_all_related_m2m_objects_with_model
  429.             cache = self._fill_related_many_to_many_cache()
File "/home/kbuzz/webapps/django/lib/python2.7/django/db/models/options.py" in _fill_related_many_to_many_cache
  443.         for klass in get_models(only_installed=False):
File "/home/kbuzz/webapps/django/lib/python2.7/django/db/models/loading.py" in get_models
  181.         self._populate()
File "/home/kbuzz/webapps/django/lib/python2.7/django/db/models/loading.py" in _populate
  67.                     self.load_app(app_name)
File "/home/kbuzz/webapps/django/lib/python2.7/django/db/models/loading.py" in load_app
  88.             models = import_module('.models', app_name)
File "/home/kbuzz/webapps/django/lib/python2.7/django/utils/importlib.py" in import_module
  35.     __import__(name)
File "/home/kbuzz/webapps/django/kb/articles/models.py" in <module>
  10. from profiles.models import CustomUser
File "/home/kbuzz/webapps/django/kb/profiles/models.py" in <module>
  1. from django.contrib.auth.models import AbstractBaseUser, BaseUserManager, PermissionsMixin

Exception Type: ImportError at /
Exception Value: cannot import name AbstractBaseUser

这是因为AbstractBaseUser没有在django 1.4.22中定义,我会重新导入所有这些并确保它们的工作比升级更难。

更新

我已将wsgi.py编辑为如下所示,然后重新启动服务器。

import os
import sys

os.environ['DJANGO_SETTINGS_MODULE'] = 'kb.settings'

from django.core.wsgi import get_wsgi_application

application = get_wsgi_application()

我收到错误

[Mon Nov 09 19:25:37 2015] [error] [client 127.0.0.1] mod_wsgi (pid=981324): Target WSGI script '/home/kbuzz/webapps/django/kb/kb/wsgi.py' cannot be loaded as Python module.
[Mon Nov 09 19:25:37 2015] [error] [client 127.0.0.1] mod_wsgi (pid=981324): Exception occurred processing WSGI script '/home/kbuzz/webapps/django/kb/kb/wsgi.py'.
[Mon Nov 09 19:25:37 2015] [error] [client 127.0.0.1] Traceback (most recent call last):
[Mon Nov 09 19:25:37 2015] [error] [client 127.0.0.1]   File "/home/kbuzz/webapps/django/kb/kb/wsgi.py", line 8, in <module>
[Mon Nov 09 19:25:37 2015] [error] [client 127.0.0.1]     application = get_wsgi_application()
[Mon Nov 09 19:25:37 2015] [error] [client 127.0.0.1]   File "/home/kbuzz/webapps/django/lib/python2.7/django/core/wsgi.py", line 14, in get_wsgi_application
[Mon Nov 09 19:25:37 2015] [error] [client 127.0.0.1]     django.setup()
[Mon Nov 09 19:25:37 2015] [error] [client 127.0.0.1]   File "/home/kbuzz/webapps/django/lib/python2.7/django/__init__.py", line 18, in setup
[Mon Nov 09 19:25:37 2015] [error] [client 127.0.0.1]     apps.populate(settings.INSTALLED_APPS)
[Mon Nov 09 19:25:37 2015] [error] [client 127.0.0.1]   File "/home/kbuzz/webapps/django/lib/python2.7/django/apps/registry.py", line 78, in populate
[Mon Nov 09 19:25:37 2015] [error] [client 127.0.0.1]     raise RuntimeError("populate() isn't reentrant")
[Mon Nov 09 19:25:37 2015] [error] [client 127.0.0.1] RuntimeError: populate() isn't reentrant

1 个答案:

答案 0 :(得分:0)

您的升级路径太长了,如果您使用的是其他应用,则可能会发生重大变化。

相反,请执行下面的分阶段升级:

1.5 -> 1.6
1.6 -> 1.7
1.7 -> 1.8 

这需要一段时间,但这就是长期保持如此重要升级的代价。