Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

in my Django project in Linux machine (in AWS) I'm using:

  • Python 3.5.1
  • Django 1.11.7

I've created virtual environment for my project and all dependencies are installed perfectly there. For the database I'm using sqlite3. See below for the version details.

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

In settings.py the DATABASES section is as below:

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

While running runserver I am getting one exception as sqlite3.NotSupportedError: URIs not supported which is generating an error django.db.utils.NotSupportedError: URIs not supported, that I am not able to fix.

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.

Note: In windows machine this my project is running fine.

Please see the traceback below:

# 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

Please help to understand and fix this error. There is no related posts in stack for this issue nor I have found anything relevant in google.

like image 984
iPaul Avatar asked Mar 26 '18 20:03

iPaul


2 Answers

1.You have to check sqlite3 version first. It should be 3.X My configuration is Python 3.7, django 2.1.7 and sqlite3. You can check sqlite3 version as below: >>import sqlite3

>>sqlite3.version '2.6.0' >>> sqlite3.sqlite_version_info (3, 6, 20)`

  1. Check in "/usr/local/lib/python3.7/site-packages/django/db/backends/sqlite3/base.py" Look for line" kwargs.update({'check_same_thread': False, 'uri': False}) If 'uri' is True, then change it to False as root. After code change, reboot your machine and run python runserver migrate This should resolve your issue.

Also, you can try changing the DATABASE['NAME'] with hardcoded db.sqli3 file name in the SETTINGS.py file.

like image 70
Jyoti Avatar answered Nov 11 '22 20:11

Jyoti


I got a similar problem. Turns out Django 2.1 is incompatible with sqlite 3.6.20. Downgrade to version 2.0.x and you should be good. The issue has been raised and is labelled "Closed bug- wontfix" here

like image 43
rogerodipo Avatar answered Nov 11 '22 21:11

rogerodipo