我在Linux机器(AWS中)的Django项目中使用:
- Python 3.5.1
- Django 1.11.7
我为我的项目创建了虚拟环境,并且所有依赖项都已经完美地安装在那里。关于数据库,我使用sqlite3。版本详情如下。
>>>import sqlite3
>>>sqlite3.version
'2.6.0'
>>>sqlite3.sqlite_version_info
(3, 7, 17)
在 settings.py 文件中,DATABASES 部分如下:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
当我运行runserver时,出现了一个异常,sqlite3.NotSupportedError: URIs not supported ,这导致了一个错误django.db.utils.NotSupportedError: URIs not supported,我无法修复它。
我已经阅读了像djangoproject.com和google.forum这样的文章,但仍然无法理解此错误的原因。 我还尝试执行python manage.py makemigrations,但同样的错误也出现了。
注意:在Windows机器上,我的项目可以正常运行。
请参见下面的跟踪:
# python manage.py runserver
Performing system checks...
System check identified no issues (0 silenced).
Unhandled exception in thread started by <function check_errors.
<locals>.wrapper at 0x7f07ff09c2f0>
Traceback (most recent call last):
File "/tech/poc/env/lib/python3.5/site-packages/django/db/backends/base/base.py", line 213, in ensure_connection
self.connect()
File "/tech/poc/env/lib/python3.5/site- packages/django/db/backends/base/base.py", line 189, in connect
self.connection = self.get_new_connection(conn_params)
File "/tech/poc/env/lib/python3.5/site-packages/django/db/backends/sqlite3/base.py", line 198, in get_new_connection
conn = Database.connect(**conn_params)
sqlite3.NotSupportedError: URIs not supported
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/tech/poc/env/lib/python3.5/site-packages/django/utils/autoreload.py", line 228, in wrapper
fn(*args, **kwargs)
File "/tech/poc/env/lib/python3.5/site-packages/django/core/management/commands/runserver.py", line 128, in inner_run
self.check_migrations()
File "/tech/poc/env/lib/python3.5/site-packages/django/core/management/base.py", line 422, in check_migrations
executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
File "/tech/poc/env/lib/python3.5/site-packages/django/db/migrations/executor.py", line 20, in __init__
self.loader = MigrationLoader(self.connection)
File "/tech/poc/env/lib/python3.5/site-packages/django/db/migrations/loader.py", line 52, in __init__
self.build_graph()
File "/tech/poc/env/lib/python3.5/site-packages/django/db/migrations/loader.py", line 209, in build_graph
self.applied_migrations = recorder.applied_migrations()
File "/tech/poc/env/lib/python3.5/site-packages/django/db/migrations/recorder.py", line 65, in applied_migrations
self.ensure_schema()
File "/tech/poc/env/lib/python3.5/site-packages/django/db/migrations/recorder.py", line 52, in ensure_schema
if self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor()):
File "/tech/poc/env/lib/python3.5/site-packages/django/db/backends/base/base.py", line 254, in cursor
return self._cursor()
File "/tech/poc/env/lib/python3.5/site-packages/django/db/backends/base/base.py", line 229, in _cursor
self.ensure_connection()
File "/tech/poc/env/lib/python3.5/site-packages/django/db/backends/base/base.py", line 213, in ensure_connection
self.connect()
File "/tech/poc/env/lib/python3.5/site-packages/django/db/utils.py", line 94, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/tech/poc/env/lib/python3.5/site-packages/django/utils/six.py", line 685, in reraise
raise value.with_traceback(tb)
File "/tech/poc/env/lib/python3.5/site-packages/django/db/backends/base/base.py", line 213, in ensure_connection
self.connect()
File "/tech/poc/env/lib/python3.5/site-packages/django/db/backends/base/base.py", line 189, in connect
self.connection = self.get_new_connection(conn_params)
File "/tech/poc/env/lib/python3.5/site-packages/django/db/backends/sqlite3/base.py", line 198, in get_new_connection
conn = Database.connect(**conn_params)
django.db.utils.NotSupportedError: URIs not supported
请帮助理解并修复此错误。在堆栈中没有与此问题相关的帖子,也没有在谷歌上找到任何相关信息。
django.db.backends.sqlite3.base
大约在第 194 行设置了uri
为True
。如果我将其注释掉,它就可以工作了。 - leech