【发布时间】:2014-01-22 20:14:27
【问题描述】:
我在 SQLite 上有一个完全可以运行的应用程序,现在为了生产,我必须将它配置为使用 MySQL。我安装了 MySQL 和 python 客户端,将我的 settings.py 更改为:
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
我想检查这个列是否存在于我的数据库中,所以在终端中我进入 python shell 并输入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)
【问题讨论】:
-
您在进行更改后是否同步了数据库?
-
@IanClark 是的,我还是犯了同样的查询错误:(
标签: python mysql django sqlite