我有一个完全可用的SQLite应用程序,现在用于生产,我不得不将它配置为使用MySQL。我安装了MySQL和Python客户端,改变了我的settings.py到:Django:匹配查询不存在和django.core.exceptions.ImproperlyConfigured
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'db_name',
'USER': 'db_user',
'PASSWORD': 'db_password',
'HOST': 'localhost', # Or an IP Address that your DB is hosted on
'PORT': '3306',
}
}
所以,现在当我运行该网站的管理部分工作正常的服务器,但是当我尝试登录到现场实际我出现以下错误:
DoesNotExist at /logins/
CustomUser matching query does not exist.
Request Method: GET
Request URL: http://127.0.0.1:8000/logins/
Django Version: 1.6
Exception Type: DoesNotExist
Exception Value:
CustomUser matching query does not exist.
Exception Location: /Library/Python/2.7/site-packages/django/db/models/query.py in get, line 307
Python Executable: /Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python
Python Version: 2.7.5
我想检查我的数据库中存在此列,所以在终端,我走进蟒蛇外壳和类型from logins.models import *
并得到了以下错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "logins/models.py", line 1, in <module>
from django.db import models
File "/Library/Python/2.7/site-packages/django/db/__init__.py", line 83, in <module>
signals.request_started.connect(reset_queries)
File "/Library/Python/2.7/site-packages/django/dispatch/dispatcher.py", line 88, in connect
if settings.DEBUG:
File "/Library/Python/2.7/site-packages/django/conf/__init__.py", line 54, in __getattr__
self._setup(name)
File "/Library/Python/2.7/site-packages/django/conf/__init__.py", line 47, in _setup
% (desc, ENVIRONMENT_VARIABLE))
django.core.exceptions.ImproperlyConfigured: Requested setting DEBUG, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
事情是,除了数据库我没有碰我的项目中的任何文件。我还有应用程序的SQLite版本,我尝试从python shell运行from logins.models import *
,现在和MySQL一样,我得到了同样的错误。之前,正如我所提到的,一切都工作得很好。
我真的很感谢一些帮助!
在此先感谢!
编辑: 代码views.py登录:
@login_required()
def index(request):
u = request.user
custom_user = CustomUser.objects.get(user=u)
info_list =Info.objects.filter(game__in=custom_user.game.all(), department__in = custom_user.department.all()).distinct()
#visible = Info.objects.filter(department__in=customuser.departments.all(), game__in=customuser.games.all())
context = RequestContext(request, {
'info_list': info_list,
})
template = loader.get_template('logins/index.html')
args = {}
args.update(csrf(request))
args['index'] = Info.objects.all()
return HttpResponse(template.render(context), args)
您做了更改后是否syncDB? –
@IanClark是的,我确实 仍然是相同的查询错误:( – lulu