我刚刚创建了一个Django项目并尝试使用虚拟环境。 我已成功安装:
django 1.9.11.
virtual environment
python 3.4.4.
pymysql
我以为我做的一切都正常,但是我无法运行django开发服务器,它在文件中给了我很多错误:
base.py
__init__.py
connections.py
err.py
在我尝试运行服务器后,它给了我这个权利:
python manage.py runserver
Performing system checks...
Unhandled exception in thread started by <function check_errors. <locals>.wrapper at
Traceback (most recent call last):
我如何解决这个问题,以便我可以使用mysql运行开发服务器? 谢谢。
回溯:
File "/Users/me/DjangoProjects/myvenv/lib/python3.4/site-packages/django/db/backends/base/base.py", line 199, in ensure_connection
self.connect()
File "/Users/me/DjangoProjects/myvenv/lib/python3.4/site-packages/django/db/backends/base/base.py", line 171, in connect
self.connection = self.get_new_connection(conn_params)
File "/Users/me/DjangoProjects/myvenv/lib/python3.4/site-packages/django/db/backends/mysql/base.py", line 268, in get_new_connection
conn = Database.connect(**conn_params)
File "/Users/me/DjangoProjects/myvenv/lib/python3.4/site-packages/pymysql/__init__.py", line 88, in Connect
return Connection(*args, **kwargs)
File "/Users/me/DjangoProjects/myvenv/lib/python3.4/site-packages/pymysql/connections.py", line 689, in __init__
self.connect()
File "/Users/me/DjangoProjects/myvenv/lib/python3.4/site-packages/pymysql/connections.py", line 907, in connect
self._request_authentication()
File "/Users/me/DjangoProjects/myvenv/lib/python3.4/site-packages/pymysql/connections.py", line 1115, in _request_authentication
auth_packet = self._read_packet()
File "/Users/me/DjangoProjects/myvenv/lib/python3.4/site-packages/pymysql/connections.py", line 982, in _read_packet
packet.check_error()
File "/Users/me/DjangoProjects/myvenv/lib/python3.4/site-packages/pymysql/connections.py", line 394, in check_error
err.raise_mysql_exception(self._data)
File "/Users/me/DjangoProjects/myvenv/lib/python3.4/site-packages/pymysql/err.py", line 120, in raise_mysql_exception
_check_mysql_exception(errinfo)
File "/Users/me/DjangoProjects/myvenv/lib/python3.4/site-packages/pymysql/err.py", line 115, in _check_mysql_exception
raise InternalError(errno, errorvalue)pymysql.err.InternalError: (1049, "Unknown database 'fundatabase'")
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/Users/me/DjangoProjects/myvenv/lib/python3.4/site- packages/django/utils/autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "/Users/me/DjangoProjects/myvenv/lib/python3.4/site-packages/django/core/management/commands/runserver.py", line 116, in inner_run
self.check(display_num_errors=True)
File "/Users/me/DjangoProjects/myvenv/lib/python3.4/site-packages/django/core/management/base.py", line 426, in check
include_deployment_checks=include_deployment_checks,
File "/Users/me/DjangoProjects/myvenv/lib/python3.4/site-packages/django/core/checks/registry.py", line 75, in run_checks
new_errors = check(app_configs=app_configs)
File "/Users/me/DjangoProjects/myvenv/lib/python3.4/site-packages/django/core/checks/model_checks.py", line 28, in check_all_models
errors.extend(model.check(**kwargs))
File "/Users/me/DjangoProjects/myvenv/lib/python3.4/site-packages/django/db/models/base.py", line 1178, in check
errors.extend(cls._check_fields(**kwargs))
File "/Users/me/DjangoProjects/myvenv/lib/python3.4/site-packages/django/db/models/base.py", line 1255, in _check_fields
errors.extend(field.check(**kwargs))
File "/Users/me/DjangoProjects/myvenv/lib/python3.4/site-packages/django/db/models/fields/__init__.py", line 925, in check
errors = super(AutoField, self).check(**kwargs)
File "/Users/me/DjangoProjects/myvenv/lib/python3.4/site-packages/django/db/models/fields/__init__.py", line 208, in check
errors.extend(self._check_backend_specific_checks(**kwargs))
File "/Users/me/DjangoProjects/myvenv/lib/python3.4/site-packages/django/db/models/fields/__init__.py", line 317, in _check_backend_specific_checks
return connections[db].validation.check_field(self, **kwargs)
File "/Users/me/DjangoProjects/myvenv/lib/python3.4/site-packages/django/db/backends/mysql/validation.py", line 18, in check_field
field_type = field.db_type(connection)
File "/Users/me/DjangoProjects/myvenv/lib/python3.4/site-packages/django/db/models/fields/__init__.py", line 625, in db_type
return connection.data_types[self.get_internal_type()] % data
File "/Users/me/DjangoProjects/myvenv/lib/python3.4/site-packages/django/db/__init__.py", line 36, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/Users/me/DjangoProjects/myvenv/lib/python3.4/site-packages/django/utils/functional.py", line 33, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/Users/me/DjangoProjects/myvenv/lib/python3.4/site-packages/django/db/backends/mysql/base.py", line 188, in data_types
if self.features.supports_microsecond_precision:
File "/Users/me/DjangoProjects/myvenv/lib/python3.4/site-packages/django/utils/functional.py", line 33, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/Users/me/DjangoProjects/myvenv/lib/python3.4/site-packages/django/db/backends/mysql/features.py", line 53, in supports_microsecond_precision
return self.connection.mysql_version >= (5, 6, 4) and Database.version_info >= (1, 2, 5)
File "/Users/me/DjangoProjects/myvenv/lib/python3.4/site-packages/django/utils/functional.py", line 33, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/Users/me/DjangoProjects/myvenv/lib/python3.4/site-packages/django/db/backends/mysql/base.py", line 363, in mysql_version
with self.temporary_connection():
文件“/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/contextlib.py”,第59行,在输入 返回下一个(self.gen) 在临时连接中输入文件“/Users/me/DjangoProjects/myvenv/lib/python3.4/site-packages/django/db/backends/base/base.py”,第564行 cursor = self.cursor() 文件“/Users/me/DjangoProjects/myvenv/lib/python3.4/site-packages/django/db/backends/base/base.py”,第231行,在游标中 cursor = self.make_debug_cursor(self._cursor()) 在_cursor中输入文件“/Users/me/DjangoProjects/myvenv/lib/python3.4/site-packages/django/db/backends/base/base.py”,第204行 self.ensure_connection() 文件“/Users/me/DjangoProjects/myvenv/lib/python3.4/site-packages/django/db/backends/base/base.py”,第199行,在ensure_connection中 self.connect() 文件“/Users/me/DjangoProjects/myvenv/lib/python3.4/site-packages/django/db/utils.py”,第95行,退出 six.reraise(dj_exc_type,dj_exc_value,traceback) 文件“/Users/me/DjangoProjects/myvenv/lib/python3.4/site-packages/django/utils/six.py”,第685行,重新加入 提高value.with_traceback(tb) 文件“/Users/me/DjangoProjects/myvenv/lib/python3.4/site-packages/django/db/backends/base/base.py”,第199行,在ensure_connection中 self.connect() 在连接文件“/Users/me/DjangoProjects/myvenv/lib/python3.4/site-packages/django/db/backends/base/base.py”,第171行 self.connection = self.get_new_connection(conn_params) get_new_connection中的文件“/Users/me/DjangoProjects/myvenv/lib/python3.4/site-packages/django/db/backends/mysql/base.py”,第268行 conn = Database.connect(** conn_params) 在Connect中输入文件“/Users/me/DjangoProjects/myvenv/lib/python3.4/site-packages/pymysql/init.py”,第88行 return Connection(* args,** kwargs) 在 init 中输入文件“/Users/me/DjangoProjects/myvenv/lib/python3.4/site-packages/pymysql/connections.py”,第689行 self.connect() 文件“/Users/me/DjangoProjects/myvenv/lib/python3.4/site-packages/pymysql/connections.py”,第907行,在连接中 self._request_authentication() 在_request_authentication中输入文件“/Users/me/DjangoProjects/myvenv/lib/python3.4/site-packages/pymysql/connections.py”,第1115行 auth_packet = self._read_packet() 在_read_packet中输入文件“/Users/me/DjangoProjects/myvenv/lib/python3.4/site-packages/pymysql/connections.py”,第982行 packet.check_error() 在check_error中输入文件“/Users/me/DjangoProjects/myvenv/lib/python3.4/site-packages/pymysql/connections.py”,第394行 err.raise_mysql_exception(self._data) 在raise_mysql_exception中输入文件“/Users/me/DjangoProjects/myvenv/lib/python3.4/site-packages/pymysql/err.py”,第120行 _check_mysql_exception(errinfo) 在_check_mysql_exception中输入文件“/Users/me/DjangoProjects/myvenv/lib/python3.4/site-packages/pymysql/err.py”,第115行 提出InternalError(错误,错误值) django.db.utils.InternalError:(1049,“未知数据库'基金数据库'”)
来自 settings.py :
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'fundatabase',
'USER' : 'root',
'PASSWORD': 'password',
'HOST': '127.0.0.1',
'PORT': '3306',
}
}
答案 0 :(得分:0)
我从来没有找到答案,但只是删除了这个项目和我的包含django和python的env。现在我能够创建没有这些错误的项目。