I am trying to upgrade a project from Django 1.6 to 1.7. I get the following error:
我正在尝试将一个项目从Django 1.6升级到1.7。我得到了以下错误:
[Thu Oct 09 14:16:41 2014] [error] [client 95.79.172.156] mod_wsgi (pid=14523): Exception occurred processing WSGI script '/home/users1/k/kisvadim/domains/mathtasks.org/django.wsgi'.
[Thu Oct 09 14:16:41 2014] [error] [client 95.79.172.156] Traceback (most recent call last):
[Thu Oct 09 14:16:41 2014] [error] [client 95.79.172.156] File "/home/users1/k/kisvadim/virtualenv/PythonEnv/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 187, in __call__
[Thu Oct 09 14:16:41 2014] [error] [client 95.79.172.156] response = self.get_response(request)
[Thu Oct 09 14:16:41 2014] [error] [client 95.79.172.156] File "/home/users1/k/kisvadim/virtualenv/PythonEnv/lib/python2.7/site-packages/django/core/handlers/base.py", line 199, in get_response
[Thu Oct 09 14:16:41 2014] [error] [client 95.79.172.156] response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
[Thu Oct 09 14:16:41 2014] [error] [client 95.79.172.156] File "/home/users1/k/kisvadim/virtualenv/PythonEnv/lib/python2.7/site-packages/django/core/handlers/base.py", line 239, in handle_uncaught_exception
[Thu Oct 09 14:16:41 2014] [error] [client 95.79.172.156] if resolver.urlconf_module is None:
[Thu Oct 09 14:16:41 2014] [error] [client 95.79.172.156] File "/home/users1/k/kisvadim/virtualenv/PythonEnv/lib/python2.7/site-packages/django/core/urlresolvers.py", line 361, in urlconf_module
[Thu Oct 09 14:16:41 2014] [error] [client 95.79.172.156] self._urlconf_module = import_module(self.urlconf_name)
[Thu Oct 09 14:16:41 2014] [error] [client 95.79.172.156] File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
[Thu Oct 09 14:16:41 2014] [error] [client 95.79.172.156] __import__(name)
[Thu Oct 09 14:16:41 2014] [error] [client 95.79.172.156] File "/home/users1/k/kisvadim/django/mathtasks/mathtasks/urls.py", line 11, in <module>
[Thu Oct 09 14:16:41 2014] [error] [client 95.79.172.156] admin.autodiscover()
[Thu Oct 09 14:16:41 2014] [error] [client 95.79.172.156] File "/home/users1/k/kisvadim/virtualenv/PythonEnv/lib/python2.7/site-packages/django/contrib/admin/__init__.py", line 23, in autodiscover
[Thu Oct 09 14:16:41 2014] [error] [client 95.79.172.156] autodiscover_modules('admin', register_to=site)
[Thu Oct 09 14:16:41 2014] [error] [client 95.79.172.156] File "/home/users1/k/kisvadim/virtualenv/PythonEnv/lib/python2.7/site-packages/django/utils/module_loading.py", line 67, in autodiscover_modules
[Thu Oct 09 14:16:41 2014] [error] [client 95.79.172.156] for app_config in apps.get_app_configs():
[Thu Oct 09 14:16:41 2014] [error] [client 95.79.172.156] File "/home/users1/k/kisvadim/virtualenv/PythonEnv/lib/python2.7/site-packages/django/apps/registry.py", line 137, in get_app_configs
[Thu Oct 09 14:16:41 2014] [error] [client 95.79.172.156] self.check_apps_ready()
[Thu Oct 09 14:16:41 2014] [error] [client 95.79.172.156] File "/home/users1/k/kisvadim/virtualenv/PythonEnv/lib/python2.7/site-packages/django/apps/registry.py", line 124, in check_apps_ready
[Thu Oct 09 14:16:41 2014] [error] [client 95.79.172.156] raise AppRegistryNotReady("Apps aren't loaded yet.")
[Thu Oct 09 14:16:41 2014] [error] [client 95.79.172.156] AppRegistryNotReady: Apps aren't loaded yet.
django.wsgi:
django.wsgi:
import os, sys
import django
virtual_env = os.path.expanduser('~/virtualenv/PythonEnv')
activate_this = os.path.join(virtual_env, 'bin/activate_this.py')
execfile(activate_this, dict(__file__=activate_this))
sys.path.insert(0, os.path.join(os.path.expanduser('~'), 'django/mathtasks'))
os.environ['DJANGO_SETTINGS_MODULE'] = 'mathtasks.settings'
django.setup()
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
Any ideas what might be causing the error and how to fix it?
你知道是什么导致了这个错误吗?
UPDATE1:
UPDATE1:
I replaced:
我更换:
from django.contrib.auth.models import User
to:
:
from django.conf import settings
User = settings.AUTH_USER_MODEL
And I get the following error:
我得到以下错误:
[Thu Oct 09 15:06:15 2014] [error] [client 95.79.172.156] mod_wsgi (pid=17128): Exception occurred processing WSGI script '/home/users1/k/kisvadim/domains/mathtasks.org/django.wsgi'.
[Thu Oct 09 15:06:15 2014] [error] [client 95.79.172.156] Traceback (most recent call last):
[Thu Oct 09 15:06:15 2014] [error] [client 95.79.172.156] File "/home/users1/k/kisvadim/virtualenv/PythonEnv/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 187, in __call__
[Thu Oct 09 15:06:15 2014] [error] [client 95.79.172.156] response = self.get_response(request)
[Thu Oct 09 15:06:15 2014] [error] [client 95.79.172.156] File "/home/users1/k/kisvadim/virtualenv/PythonEnv/lib/python2.7/site-packages/django/core/handlers/base.py", line 199, in get_response
[Thu Oct 09 15:06:15 2014] [error] [client 95.79.172.156] response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
[Thu Oct 09 15:06:15 2014] [error] [client 95.79.172.156] File "/home/users1/k/kisvadim/virtualenv/PythonEnv/lib/python2.7/site-packages/django/core/handlers/base.py", line 239, in handle_uncaught_exception
[Thu Oct 09 15:06:15 2014] [error] [client 95.79.172.156] if resolver.urlconf_module is None:
[Thu Oct 09 15:06:15 2014] [error] [client 95.79.172.156] File "/home/users1/k/kisvadim/virtualenv/PythonEnv/lib/python2.7/site-packages/django/core/urlresolvers.py", line 361, in urlconf_module
[Thu Oct 09 15:06:15 2014] [error] [client 95.79.172.156] self._urlconf_module = import_module(self.urlconf_name)
[Thu Oct 09 15:06:15 2014] [error] [client 95.79.172.156] File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
[Thu Oct 09 15:06:15 2014] [error] [client 95.79.172.156] __import__(name)
[Thu Oct 09 15:06:15 2014] [error] [client 95.79.172.156] File "/home/users1/k/kisvadim/django/mathtasks/mathtasks/urls.py", line 6, in <module>
[Thu Oct 09 15:06:15 2014] [error] [client 95.79.172.156] from utils.views import SniptRegistrationView
[Thu Oct 09 15:06:15 2014] [error] [client 95.79.172.156] File "/home/users1/k/kisvadim/django/mathtasks/utils/views.py", line 1, in <module>
[Thu Oct 09 15:06:15 2014] [error] [client 95.79.172.156] from registration.backends.default.views import RegistrationView
[Thu Oct 09 15:06:15 2014] [error] [client 95.79.172.156] File "/home/users1/k/kisvadim/django/mathtasks/registration/backends/default/views.py", line 7, in <module>
[Thu Oct 09 15:06:15 2014] [error] [client 95.79.172.156] from registration.views import ActivationView as BaseActivationView
[Thu Oct 09 15:06:15 2014] [error] [client 95.79.172.156] File "/home/users1/k/kisvadim/django/mathtasks/registration/views.py", line 11, in <module>
[Thu Oct 09 15:06:15 2014] [error] [client 95.79.172.156] from registration.forms import RegistrationForm
[Thu Oct 09 15:06:15 2014] [error] [client 95.79.172.156] File "/home/users1/k/kisvadim/django/mathtasks/registration/forms.py", line 159, in <module>
[Thu Oct 09 15:06:15 2014] [error] [client 95.79.172.156] class UserProfileForm(forms.ModelForm):
[Thu Oct 09 15:06:15 2014] [error] [client 95.79.172.156] File "/home/users1/k/kisvadim/virtualenv/PythonEnv/lib/python2.7/site-packages/django/forms/models.py", line 284, in __new__
[Thu Oct 09 15:06:15 2014] [error] [client 95.79.172.156] opts.help_texts, opts.error_messages)
[Thu Oct 09 15:06:15 2014] [error] [client 95.79.172.156] File "/home/users1/k/kisvadim/virtualenv/PythonEnv/lib/python2.7/site-packages/django/forms/models.py", line 184, in fields_for_model
[Thu Oct 09 15:06:15 2014] [error] [client 95.79.172.156] opts = model._meta
[Thu Oct 09 15:06:15 2014] [error] [client 95.79.172.156] AttributeError: 'str' object has no attribute '_meta'
UPDATE 2:
更新2:
I replaced:
我更换:
from django.contrib.auth.models import User
to:
:
from django.contrib.auth import get_user_model
User = get_user_model()
and:
和:
models.ForeignKey(settings.AUTH_USER_MODEL)
And I get the following error:
我得到以下错误:
[Thu Oct 09 16:10:52 2014] [error] No handlers could be found for logger "django.request"
[Thu Oct 09 16:10:52 2014] [error] [client 95.79.172.156] mod_wsgi (pid=31421): Exception occurred processing WSGI script '/home/users1/k/kisvadim/domains/mathtasks.org/django.wsgi'.
[Thu Oct 09 16:10:52 2014] [error] [client 95.79.172.156] Traceback (most recent call last):
[Thu Oct 09 16:10:52 2014] [error] [client 95.79.172.156] File "/home/users1/k/kisvadim/virtualenv/PythonEnv/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 187, in __call__
[Thu Oct 09 16:10:52 2014] [error] [client 95.79.172.156] response = self.get_response(request)
[Thu Oct 09 16:10:52 2014] [error] [client 95.79.172.156] File "/home/users1/k/kisvadim/virtualenv/PythonEnv/lib/python2.7/site-packages/django/core/handlers/base.py", line 199, in get_response
[Thu Oct 09 16:10:52 2014] [error] [client 95.79.172.156] response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
[Thu Oct 09 16:10:52 2014] [error] [client 95.79.172.156] File "/home/users1/k/kisvadim/virtualenv/PythonEnv/lib/python2.7/site-packages/django/core/handlers/base.py", line 239, in handle_uncaught_exception
[Thu Oct 09 16:10:52 2014] [error] [client 95.79.172.156] if resolver.urlconf_module is None:
[Thu Oct 09 16:10:52 2014] [error] [client 95.79.172.156] File "/home/users1/k/kisvadim/virtualenv/PythonEnv/lib/python2.7/site-packages/django/core/urlresolvers.py", line 361, in urlconf_module
[Thu Oct 09 16:10:52 2014] [error] [client 95.79.172.156] self._urlconf_module = import_module(self.urlconf_name)
[Thu Oct 09 16:10:52 2014] [error] [client 95.79.172.156] File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
[Thu Oct 09 16:10:52 2014] [error] [client 95.79.172.156] __import__(name)
[Thu Oct 09 16:10:52 2014] [error] [client 95.79.172.156] File "/home/users1/k/kisvadim/django/mathtasks/mathtasks/urls.py", line 6, in <module>
[Thu Oct 09 16:10:52 2014] [error] [client 95.79.172.156] from utils.views import SniptRegistrationView
[Thu Oct 09 16:10:52 2014] [error] [client 95.79.172.156] File "/home/users1/k/kisvadim/django/mathtasks/utils/views.py", line 1, in <module>
[Thu Oct 09 16:10:52 2014] [error] [client 95.79.172.156] from registration.backends.default.views import RegistrationView
[Thu Oct 09 16:10:52 2014] [error] [client 95.79.172.156] File "/home/users1/k/kisvadim/django/mathtasks/registration/backends/default/views.py", line 6, in <module>
[Thu Oct 09 16:10:52 2014] [error] [client 95.79.172.156] from registration.models import RegistrationProfile
[Thu Oct 09 16:10:52 2014] [error] [client 95.79.172.156] File "/home/users1/k/kisvadim/django/mathtasks/registration/models.py", line 9, in <module>
[Thu Oct 09 16:10:52 2014] [error] [client 95.79.172.156] User = get_user_model()
[Thu Oct 09 16:10:52 2014] [error] [client 95.79.172.156] File "/home/users1/k/kisvadim/virtualenv/PythonEnv/lib/python2.7/site-packages/django/contrib/auth/__init__.py", line 136, in get_user_model
[Thu Oct 09 16:10:52 2014] [error] [client 95.79.172.156] return django_apps.get_model(settings.AUTH_USER_MODEL)
[Thu Oct 09 16:10:52 2014] [error] [client 95.79.172.156] File "/home/users1/k/kisvadim/virtualenv/PythonEnv/lib/python2.7/site-packages/django/apps/registry.py", line 199, in get_model
[Thu Oct 09 16:10:52 2014] [error] [client 95.79.172.156] self.check_models_ready()
[Thu Oct 09 16:10:52 2014] [error] [client 95.79.172.156] File "/home/users1/k/kisvadim/virtualenv/PythonEnv/lib/python2.7/site-packages/django/apps/registry.py", line 131, in check_models_ready
[Thu Oct 09 16:10:52 2014] [error] [client 95.79.172.156] raise AppRegistryNotReady("Models aren't loaded yet.")
[Thu Oct 09 16:10:52 2014] [error] [client 95.79.172.156] AppRegistryNotReady: Models aren't loaded yet.
12 个解决方案
#1
71
see http://django.readthedocs.org/en/latest/releases/1.7.html#standalone-scripts
看到http://django.readthedocs.org/en/latest/releases/1.7.html standalone-scripts
import django
django.setup()
#2
69
I had a similar (the same?) isssue when upgrading to Django 1.7. In may case, it was enough to update the wsgi file: replace
在升级到Django 1.7时,我有一个类似的isssue。在5月份,更新wsgi文件:replace就足够了
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
with
与
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
#3
16
I was looking through all these thread to get celery working on windows (with this particular error message) and I just want to emphasize putting
我查看了所有这些线程以使芹菜在windows上工作(带有这个特定的错误信息),我只想强调put
import django
django.setup()
at the top of your tasks.py file, this is finally what got it working for me.
在你的任务的顶端。py文件,这就是它对我起作用的原因。
#4
12
INSTALLED_APPS
Had an missing comma in the array, that caused the error for me.
INSTALLED_APPS在数组中缺少一个逗号,这导致了我的错误。
#5
9
I got this error when I tried to import models from the app's __init__.py
, which is not possible.
当我试图从应用的__init__导入模型时,我犯了这个错误。这是不可能的。
#6
5
In configuration uwsgi application file ( like uwsgi.ini ) replace:
配置uwsgi应用程序文件(如uwsgi)。ini)替换:
module = django.core.handlers.wsgi:WSGIHandler()
on
在
module=django.core.wsgi:get_wsgi_application()
#7
1
settings.AUTH_USER_MODEL
is a string (that's why you get AttributeError: 'str' object has no attribute '_meta'
- it expects a Model) and should be used only on ForeignKey
declarations:
设置。AUTH_USER_MODEL是一个字符串(这就是为什么您会得到AttributeError:“str”对象没有属性“_meta”——它需要一个模型),并且只能在外部的声明中使用:
class Article(models.Model): author = models.ForeignKey(settings.AUTH_USER_MODEL)
If you want to refer to your user model somewhere else you need to use get_user_model
:
如果您想在其他地方引用您的用户模型,您需要使用get_user_model:
from django.contrib.auth import get_user_model UserModel = get_user_model()
#8
1
I got this error when moving to a different PC and forgetting to install psycopg2
in my venv and when using 'ENGINE': 'django.db.backends.postgresql',
in my settings.
当我转移到另一台PC上,忘记在我的venv中安装psycopg2时,以及在使用“ENGINE”时,我犯了这个错误:“django.db.backends”。postgresql的,在我的设置。
Perhaps it can be useful to someone else.
也许它对别人有用。
#9
0
In my case, I forgot to add one of my sub-applications inside INSTALLED_APPS
.
在我的例子中,我忘记在INSTALLED_APPS中添加我的一个子应用程序。
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'basketball',
'basketball.area',
'basketball.game',
'basketball.player',
]
#10
0
In my case the error was caused when I upgraded celery to 4.x and I had this in my INSTALLED_APPS: kombu.transport.django
. Removing that resolved the issue. Seems it is mostly caused by some incorrect load of django itself.
在我的例子中,当我把芹菜升级到4时,错误就出现了。我在我的INSTALLED_APPS中有:kombu.transport.django。消除这个问题解决了问题。似乎这主要是由django本身的错误负载造成的。
#11
-3
Just reinstall Django using the command line, not in Pycharm helped to me.
使用命令行重新安装Django,而不是使用Pycharm。
#12
-3
It could be any reason. In my case, I updated my python version outside of my virtual environment, but my virtualenv was still the old version, that makes the error. I deleted the env and build it again using the newer version, and it worked.
这可能是任何原因。在我的例子中,我在虚拟环境之外更新了python版本,但是我的virtualenv仍然是旧版本,这导致了错误。我删除了env,并使用更新的版本重新构建它,它成功了。
#1
71
see http://django.readthedocs.org/en/latest/releases/1.7.html#standalone-scripts
看到http://django.readthedocs.org/en/latest/releases/1.7.html standalone-scripts
import django
django.setup()
#2
69
I had a similar (the same?) isssue when upgrading to Django 1.7. In may case, it was enough to update the wsgi file: replace
在升级到Django 1.7时,我有一个类似的isssue。在5月份,更新wsgi文件:replace就足够了
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
with
与
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
#3
16
I was looking through all these thread to get celery working on windows (with this particular error message) and I just want to emphasize putting
我查看了所有这些线程以使芹菜在windows上工作(带有这个特定的错误信息),我只想强调put
import django
django.setup()
at the top of your tasks.py file, this is finally what got it working for me.
在你的任务的顶端。py文件,这就是它对我起作用的原因。
#4
12
INSTALLED_APPS
Had an missing comma in the array, that caused the error for me.
INSTALLED_APPS在数组中缺少一个逗号,这导致了我的错误。
#5
9
I got this error when I tried to import models from the app's __init__.py
, which is not possible.
当我试图从应用的__init__导入模型时,我犯了这个错误。这是不可能的。
#6
5
In configuration uwsgi application file ( like uwsgi.ini ) replace:
配置uwsgi应用程序文件(如uwsgi)。ini)替换:
module = django.core.handlers.wsgi:WSGIHandler()
on
在
module=django.core.wsgi:get_wsgi_application()
#7
1
settings.AUTH_USER_MODEL
is a string (that's why you get AttributeError: 'str' object has no attribute '_meta'
- it expects a Model) and should be used only on ForeignKey
declarations:
设置。AUTH_USER_MODEL是一个字符串(这就是为什么您会得到AttributeError:“str”对象没有属性“_meta”——它需要一个模型),并且只能在外部的声明中使用:
class Article(models.Model): author = models.ForeignKey(settings.AUTH_USER_MODEL)
If you want to refer to your user model somewhere else you need to use get_user_model
:
如果您想在其他地方引用您的用户模型,您需要使用get_user_model:
from django.contrib.auth import get_user_model UserModel = get_user_model()
#8
1
I got this error when moving to a different PC and forgetting to install psycopg2
in my venv and when using 'ENGINE': 'django.db.backends.postgresql',
in my settings.
当我转移到另一台PC上,忘记在我的venv中安装psycopg2时,以及在使用“ENGINE”时,我犯了这个错误:“django.db.backends”。postgresql的,在我的设置。
Perhaps it can be useful to someone else.
也许它对别人有用。
#9
0
In my case, I forgot to add one of my sub-applications inside INSTALLED_APPS
.
在我的例子中,我忘记在INSTALLED_APPS中添加我的一个子应用程序。
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'basketball',
'basketball.area',
'basketball.game',
'basketball.player',
]
#10
0
In my case the error was caused when I upgraded celery to 4.x and I had this in my INSTALLED_APPS: kombu.transport.django
. Removing that resolved the issue. Seems it is mostly caused by some incorrect load of django itself.
在我的例子中,当我把芹菜升级到4时,错误就出现了。我在我的INSTALLED_APPS中有:kombu.transport.django。消除这个问题解决了问题。似乎这主要是由django本身的错误负载造成的。
#11
-3
Just reinstall Django using the command line, not in Pycharm helped to me.
使用命令行重新安装Django,而不是使用Pycharm。
#12
-3
It could be any reason. In my case, I updated my python version outside of my virtual environment, but my virtualenv was still the old version, that makes the error. I deleted the env and build it again using the newer version, and it worked.
这可能是任何原因。在我的例子中,我在虚拟环境之外更新了python版本,但是我的virtualenv仍然是旧版本,这导致了错误。我删除了env,并使用更新的版本重新构建它,它成功了。