centos部署Django项目时出现如下错误,查询相关资料后发现是SQLite 数据库的版本问题,出错信息大概说了问题的出现在哪里,但是看着头疼,不知从何入手,解决方法就是在这个base.py的大概194行左右,有个True。这里出了问题。
但是并没有告诉你怎么修改这里的代码。这是sqlite3版本3.7的通病,安装3.8的就可以,这里我采用修改源码的方式,直接打开。解决方法是进入/www/env/mysite/lib/python3.6/site-packages/django/db/backends/sqlite3/base.py
出错的位置把True改为False
注意这是我出错的位置,路径不一样,出错的位置也不一样。
出错信息如下:
System check identified no issues (0 silenced).
Unhandled exception in thread started by
Traceback (most recent call last):
File “/www/env/mysite/lib/python3.6/site-packages/django/db/backends/base/base.py”, line 216, in ensure_connection
self.connect()
File “/www/env/mysite/lib/python3.6/site-packages/django/db/backends/base/base.py”, line 194, in connect
self.connection = self.get_new_connection(conn_params)
File “/www/env/mysite/lib/python3.6/site-packages/django/db/backends/sqlite3/base.py”, line 159, 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 “/www/env/mysite/lib/python3.6/site-packages/django/utils/autoreload.py”, line 225, in wrapper
fn(*args, **kwargs)
File “/www/env/mysite/lib/python3.6/site-packages/django/core/management/commands/runserver.py”, line 120, in inner_run
self.check_migrations()
File “/www/env/mysite/lib/python3.6/site-packages/django/core/management/base.py”, line 442, in check_migrations
executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
File “/www/env/mysite/lib/python3.6/site-packages/django/db/migrations/executor.py”, line 18, in init
self.loader = MigrationLoader(self.connection)
File “/www/env/mysite/lib/python3.6/site-packages/django/db/migrations/loader.py”, line 49, in init
self.build_graph()
File “/www/env/mysite/lib/python3.6/site-packages/django/db/migrations/loader.py”, line 212, in build_graph
self.applied_migrations = recorder.applied_migrations()
File “/www/env/mysite/lib/python3.6/site-packages/django/db/migrations/recorder.py”, line 61, in applied_migrations
if self.has_table():
File “/www/env/mysite/lib/python3.6/site-packages/django/db/migrations/recorder.py”, line 44, in has_table
return self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor())
File “/www/env/mysite/lib/python3.6/site-packages/django/db/backends/base/base.py”, line 255, in cursor
return self._cursor()
File “/www/env/mysite/lib/python3.6/site-packages/django/db/backends/base/base.py”, line 232, in _cursor
self.ensure_connection()
File “/www/env/mysite/lib/python3.6/site-packages/django/db/backends/base/base.py”, line 216, in ensure_connection
self.connect()
File “/www/env/mysite/lib/python3.6/site-packages/django/db/utils.py”, line 89, in exit
raise dj_exc_value.with_traceback(traceback) from exc_value
File “/www/env/mysite/lib/python3.6/site-packages/django/db/backends/base/base.py”, line 216, in ensure_connection
self.connect()
File “/www/env/mysite/lib/python3.6/site-packages/django/db/backends/base/base.py”, line 194, in connect
self.connection = self.get_new_connection(conn_params)
File “/www/env/mysite/lib/python3.6/site-packages/django/db/backends/sqlite3/base.py”, line 159, in get_new_connection
conn = Database.connect(**conn_params)
django.db.utils.NotSupportedError: URIs not supported
解决办法:利用vim命令打开出错的位置
vim /www/env/mysite/lib/python3.6/site-packages/django/db/backends/sqlite3/base.py
[root@localhost myblog]# vim /www/env/mysite/lib/python3.6/site-packages/django/db/backends/sqlite3/base.py