sqlite 如何修复错误:django.db.utils.NotSupportedError:不支持URI

zynd9foi  于 2022-12-23  发布在  SQLite
关注(0)|答案(4)|浏览(212)

在Linux机器(AWS)上Django项目中,我使用了:

  • Python 3.5.1语言
  • 强哥1.11.7

我已经为我的项目创建了虚拟环境,所有的依赖项都安装得很好。对于数据库,我使用的是sqlite3。请参阅下面的版本细节。

>>>import sqlite3
>>>sqlite3.version
'2.6.0'
>>>sqlite3.sqlite_version_info
(3, 7, 17)

settings. py中,* 数据库 * 部分如下所示:

DATABASES = {
   'default': {
      'ENGINE': 'django.db.backends.sqlite3',
      'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
   }
}

运行runserver时,我收到一个异常,如sqlite3.NotSupportedError:URI不受支持这将生成错误django. db. utils. NotSupportedError:URI不受支持,我无法修复。
I have gone through the posts like djangoproject.com and google.forum, but still not able to understand the reason for this error. I also tried to do python manage.py makemigrations but same error coming for that also.
注:在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

请帮助理解和修复这个错误。没有相关的文章在堆栈为这个问题,我也没有发现任何相关的谷歌。

weylhg0b

weylhg0b1#

我遇到了一个类似的问题。原来Django 2.1与sqlite 3.6.20不兼容。降级到版本2.0.x,你应该会很好。这个问题已经提出,并标记为“关闭的bug- wontfix”here

bgtovc5b

bgtovc5b2#

1.您必须先检查sqlite3版本。它应该是3.X我的配置是Python 3.7django 2.1.7sqlite3。您可以检查sqlite3版本如下:>>import sqlite3
一米五氮一x '2.6.0'一米六氮一x(3,6,20)'
1.签入"/usr/local/lib/python3.7/site-packages/django/db/backends/sqlite3/base.py"查找行”kwargs.update({'check_same_thread': False, 'uri': False})如果“uri”为True,则以root用户身份将其更改为False。更改代码后,重新启动计算机并运行python runserver migrate这应该可以解决您的问题。
此外,您可以尝试在SETTINGS.py文件中使用硬编码的db.sqli3文件名来更改DATABASE['NAME']。

ewm0tg9j

ewm0tg9j3#

检查BASE_DIR设置中指定的路径。

vmdwslir

vmdwslir4#

我在Ubuntu上连接Postgresql时也遇到了同样的问题。我把Django的版本从最新版降级到了3.2.15。这为我解决了这个问题。我希望这能有所帮助。

相关问题