How to fix error: django.db.utils.NotSupportedError: URIs not supported

这个问题呢,很操蛋,半个下午都在弄这个花里胡哨的问题,国内的博客,没看到有正面解决问题的,写的东西也不全,话都是一半一半的说。

看了一部分帖子,给了大概的想法,下面让我们来看一下这个问题的回答和具体的代码。

一、question:

 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

二、answer:I have the same problem, it's broke on my machine, but all my co-workers don't get the bug. I debugged in django's code, and found that in django.db.backends.sqlite3.base on about line 194 it sets uri True. If i comment that out, it works.

这个answer没有直面说解决方法,说了问题的出现在哪里,就是在这个base.py的大概194行左右,有个True。这里出了问题。

但是并没有告诉你怎么修改这里的代码。

三、solution:原因分析,这是sqlite3版本3.7的通病,安装3.8的就可以,这里我采用修改源码的方式,直接打开。

"/home/python3/lib/python3.6/site-packages/django/db/backends/sqlite3/base.py"这个文件,修改修改大概198行,通过搜索uri查找。
# between multiple threads. The safe-guarding will be handled at a
        # higher level by the `BaseDatabaseWrapper.allow_thread_sharing`
        # property. This is necessary as the shareability is disabled by
        # default in pysqlite and it cannot be changed once a connection is
        # opened.
        if 'check_same_thread' in kwargs and kwargs['check_same_thread']:
            warnings.warn(
                'The `check_same_thread` option was provided and set to '
                'True. It will be overridden with False. Use the '
                '`DatabaseWrapper.allow_thread_sharing` property instead '
                'for controlling thread shareability.',
                RuntimeWarning
            )
        kwargs.update({'check_same_thread': False})
        if self.features.can_share_in_memory_db:
            kwargs.update({'uri': False})  #这里原来是True,修改为False就可以了
        return kwargs

把上面的uri对应True修改为False就ok了。

后面那个error就无伤大雅了,能启动就ok了,换一波端口就ok。

四、附加安装3.8的方法

1. wget http://www.sqlite.org/2015/sqlite-autoconf-3081101.tar.gz 

2.tar -xvzf sqlite-autoconf-3081101.tar.gz 

3.编译安装:

  (1)./configure

  (2)make

  (3)sudo make install

  (4)sudo ldconfig          

4.检查一波

这个结果的话:起飞了解下。

我觉得我这篇博客写的很详细了,如果想要转发一波的,请把在下的链接地址贴一波,不胜荣幸。

这里大家可能会有一些疑问,怎么前面3.5后面3.6,我的问题解决了。之前的问题那些报错也找不到了,就随便找了别人犯的同类错误error粘了上去,大家理解流程就好,细节嘛,自己的问题得到解决就ok。

  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值