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

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

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

一、question:


 
 
  1. The above exception was the direct cause of the following exception:
  2. Traceback (most recent call last):
  3. File "/tech/poc/env/lib/python3.5/site-packages/django/utils/autoreload.py", line 228, in wrapper
  4. fn(*args, **kwargs)
  5. File "/tech/poc/env/lib/python3.5/site-packages/django/core/management/commands/runserver.py", line 128, in inner_run
  6. self.check_migrations()
  7. File "/tech/poc/env/lib/python3.5/site-packages/django/core/management/base.py", line 422, in check_migrations
  8. executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
  9. File "/tech/poc/env/lib/python3.5/site-packages/django/db/migrations/executor.py", line 20, in __init__
  10. self.loader = MigrationLoader(self.connection)
  11. File "/tech/poc/env/lib/python3.5/site-packages/django/db/migrations/loader.py", line 52, in __init__
  12. self.build_graph()
  13. File "/tech/poc/env/lib/python3.5/site-packages/django/db/migrations/loader.py", line 209, in build_graph
  14. self.applied_migrations = recorder.applied_migrations()
  15. File "/tech/poc/env/lib/python3.5/site-packages/django/db/migrations/recorder.py", line 65, in applied_migrations
  16. self.ensure_schema()
  17. File "/tech/poc/env/lib/python3.5/site-packages/django/db/migrations/recorder.py", line 52, in ensure_schema
  18. if self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor()):
  19. File "/tech/poc/env/lib/python3.5/site-packages/django/db/backends/base/base.py", line 254, in cursor
  20. return self._cursor()
  21. File "/tech/poc/env/lib/python3.5/site-packages/django/db/backends/base/base.py", line 229, in _cursor
  22. self.ensure_connection()
  23. File "/tech/poc/env/lib/python3.5/site-packages/django/db/backends/base/base.py", line 213, in ensure_connection
  24. self.connect()
  25. File "/tech/poc/env/lib/python3.5/site-packages/django/db/utils.py", line 94, in __exit__
  26. six.reraise(dj_exc_type, dj_exc_value, traceback)
  27. File "/tech/poc/env/lib/python3.5/site-packages/django/utils/six.py", line 685, in reraise
  28. raise value.with_traceback(tb)
  29. File "/tech/poc/env/lib/python3.5/site-packages/django/db/backends/base/base.py", line 213, in ensure_connection
  30. self.connect()
  31. File "/tech/poc/env/lib/python3.5/site-packages/django/db/backends/base/base.py", line 189, in connect
  32. self.connection = self.get_new_connection(conn_params)
  33. File "/tech/poc/env/lib/python3.5/site-packages/django/db/backends/sqlite3/base.py", line 198, in get_new_connection
  34. conn = Database.connect(**conn_params)
  35. 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查找。
 
 

 
 
  1. # between multiple threads. The safe-guarding will be handled at a
  2. # higher level by the `BaseDatabaseWrapper.allow_thread_sharing`
  3. # property. This is necessary as the shareability is disabled by
  4. # default in pysqlite and it cannot be changed once a connection is
  5. # opened.
  6. if 'check_same_thread' in kwargs and kwargs[ 'check_same_thread']:
  7. warnings.warn(
  8. 'The `check_same_thread` option was provided and set to '
  9. 'True. It will be overridden with False. Use the '
  10. '`DatabaseWrapper.allow_thread_sharing` property instead '
  11. 'for controlling thread shareability.',
  12. RuntimeWarning
  13. )
  14. kwargs.update({ 'check_same_thread': False})
  15. if self.features.can_share_in_memory_db:
  16. kwargs.update({ 'uri': False}) #这里原来是True,修改为False就可以了
  17. 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。

原文链接:mezhuangzhuang



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值