我有一個完全可用的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