50

I've cloned a django project to a Centos 7 vps and I'm trying to run it now, but I get this error when trying to migrate:

$ python manage.py migrate
django.core.exceptions.ImproperlyConfigured: SQLite 3.8.3 or later is required (found 3.7.17).

When I checked the version for sqlite, it was 3.7.17, so I downloaded the newest version from sqlite website and replaced it with the old one, and now when I version it, it gives:

$ sqlite3 --version
3.27.2 2019-02-25 16:06:06 bd49a8271d650fa89e446b42e513b595a717b9212c91dd384aab871fc1d0f6d7

Still when I try to migrate the project, I get the exact same message as before which means the newer version is not found. I'm new to linux and would appreciate any help.

SIMMORSAL
  • 1,402
  • 1
  • 16
  • 32
  • 3
    The version of the standalone sqlite3 executable is irrelevant, it's the version of the Python library that is important. – Daniel Roseman Apr 14 '19 at 11:12
  • 2
    @DanielRoseman Oh. So then how can I update that? I tried `pip install pysqlite` and it installed it, but since I have python 3, it complained: >pysqlite is not supported on Python 3. When using Python 3, use the sqlite3 module from the standard library. – SIMMORSAL Apr 14 '19 at 12:59
  • Does this answer your question? [ImproperlyConfigured('SQLite 3.8.3 or later is required (found %s).' % Database.sqlite\_version)](https://stackoverflow.com/questions/60826836/improperlyconfiguredsqlite-3-8-3-or-later-is-required-found-s-database) – kloddant Sep 16 '21 at 13:24

14 Answers14

65

I got the same error in CentOS 7.6 and Python 3.7.3 versions. I think you are using Django 2.2.* some version. In latest of Django 2.2, they changed the SQLIte version, that cause of your problem.

This is the release notes of Django 2.2 about SQLite.

The minimum supported version of SQLite is increased from 3.7.15 to 3.8.3.

So I found 3 steps to solve this problem,


  • Downgrade Django Version

So you can install latest version of Django 2.1 by using this command, which mean you're going to downgrade your Django version.

pip install Django==2.1.*

or you can followup below steps as well to keep the latest version Django. I directly get the steps from Upgrading SQLite on CentOS to 3.8.3 or Later article.

You can download the latest sqlite version from here.

wget https://www.sqlite.org/2019/sqlite-autoconf-3280000.tar.gz
tar zxvf sqlite-autoconf-3280000.tar.gz
./configure
make
sudo make install

We've installed to the latest version, but the problem is same. Here,

>>> import sqlite3
>>> sqlite3.sqlite_version
'3.7.17'

In the article, they've mentioned about LD_RUN_PATH and LD_LIBRARY_PATH paths.

Then make sure to compile python again using the LD_RUN_PATH environment variable. It is better to use this variable over LD_LIBRARY_PATH. Using LD_LIBRARY_PATH - whenever python is run it will look for linked libraries with that path. What we want is for the libraries to be cooked into python at link time - compile time.

So based on the article, we can do the similar thing,

cd /opt/Python-x.y.z
LD_RUN_PATH=/usr/local/lib  ./configure
LD_RUN_PATH=/usr/local/lib make
LD_RUN_PATH=/usr/local/lib make altinstall

Then try again,

>>> import sqlite3
>>> sqlite3.sqlite_version
'3.31.1'

Here we go, one thing they've mentioned,

If you do not use LD_RUN_PATH, then you have to make sure that the LD_RUN_PATH environment variable is set to /usr/local/lib for every user that is going to run python - which can be really annoying to do.


This is same as the previous one and based on LD_LIBRARY_PATH approach. Here is the steps from the article,

$ wget https://www.sqlite.org/2018/sqlite-autoconf-3240000.tar.gz
$ tar zxvf sqlite-autoconf-3240000.tar.gz
$ ./configure --prefix=/usr/local
$ make
$ sudo make install
$
$ python3.6 -c "import sqlite3; print(sqlite3.sqlite_version)"
3.7.17
$
$ export LD_LIBRARY_PATH=/usr/local/lib
$ python3.6 -c "import sqlite3; print(sqlite3.sqlite_version)"
3.24.0

If the last two steps didn't work, please comment below with the error you got and I'll find another solution for you.

Kushan Gunasekera
  • 7,268
  • 6
  • 44
  • 58
  • 10
    It is correct that the SQLlite version requirement did change in Django 2.2.x, but if someone is cloning a project they've already deployed elsewhere, simply installing Django 2.1.x instead of 2.2.x or greater isn't going to help them at all if their project needs 2.2 or greater. Also, 2.1 is now end of life. – Joe May 03 '20 at 18:41
  • 1
    The last step was working for me. Thank you! – Manzurul Hoque Rumi Jan 14 '21 at 19:11
  • you're welcome @ManzurulHoqueRumi, glad to hear that. – Kushan Gunasekera Jan 15 '21 at 19:03
  • 1
    Hi, I am using a version of python installed with brew for linux. Do you happen to know how to implement this solution there? – Wold Feb 25 '21 at 08:47
  • 2
    Option 2 worked like a charm for me to install Python version 3.9.6 from sources on an old Mac OSX 10.9 machine. Adding this comment, just in case it helps anyone coming here from Mac – Sarfraaz Ahmed Aug 18 '21 at 12:49
  • @Wold I didn't work with brew, sorry. So which step you got stuck? – Kushan Gunasekera Aug 18 '21 at 13:05
  • Glad to hear that @SarfraazAhmed! – Kushan Gunasekera Aug 18 '21 at 13:06
  • 1
    I did `setenv LD_RUN_PATH "/mypath/sqlite/lib"` `python -c "import sqlite3; print(sqlite3.sqlite_version)"` shows `3.29.0` I am still hitting the error. Is there something else i need to check? – Jean Oct 11 '22 at 18:54
33

I solved a similar situation with the following patches of code. Follow these steps that I used on my own centos7 & everything should be alright. Just remember to let your centos7 know that you are calling python3 not just python otherwise it will call the default python2 followed by a series of errors in your virtualenv.

Installing python3 (from source):

cd ~
wget https://www.python.org/ftp/python/3.7.3/Python-3.7.3.tar.xz
tar xJf Python-3.7.3.tar.xz
cd Python-3.7.3
./configure
make && make install
export PATH=$HOME/opt/python-3.7.3/bin:$PATH

Then run: source .bash_profile

Confirming by

python3 --version
Python 3.7.3 

Installing your sqlite3 (from source):

$ cd ~
$ wget https://www.sqlite.org/2019/sqlite-autoconf-3290000.tar.gz
$ tar zxvf sqlite-autoconf-3290000.tar.gz
cd sqlite-autoconf-3290000

$./configure --prefix=$HOME/opt/sqlite
$ make && make install

Now this is what you should also remember to do for centos7 know where to look for your python3 and not defaulting to python2. On your .bash_profile copy & past this piece of code or edit the paths accordingly:

export PATH=$HOME/opt/sqlite/bin:$PATH
export LD_LIBRARY_PATH=$HOME/opt/sqlite/lib
export LD_RUN_PATH=$HOME/opt/sqlite/lib

Make it permanent by running: source .bash_profile and you are done with sqlite3 version >= 3.8. Confirm it by:

sqlite3 --version 
3.29.0 2019-07-10 17:32:03

And then you can continue to use python3 to install python3 modules like django-2.2.

python3.7 -m pip3 install virtualenv

(myvenv37)[me@test my_project]$ python3.7 -m pip3 install django
Successfully installed django-2.2.3 pytz-2019.1 sqlparse-0.3.0

Remember, it is

PYTHON3.7 -m pip3 install MODULE

(myvenv37)[me@test my_project]$ python3.7 manage.py runserver 

and the server should be running.

So, to conclude, in the case above it was migrate, & should look like this:

(venv)[me@test my_project]$ python3.7 manage.py migrate
Laenka-Oss
  • 939
  • 2
  • 17
  • 25
21

As this was about Centos7, you can use the Fedora package to upgrade the Centos sqlite package:

wget https://kojipkgs.fedoraproject.org//packages/sqlite/3.8.11/1.fc21/x86_64/sqlite-3.8.11-1.fc21.x86_64.rpm

sudo yum install sqlite-3.8.11-1.fc21.x86_64.rpm

(from: https://www.reddit.com/r/linuxadmin/comments/c9hy5w/trying_to_upgrade_sqlite_3717_to_version_38_on/ezrtbkm/?utm_source=reddit&utm_medium=web2x&context=3)

This seems to work, although I'm never sure if doing this is really an ideal solution to a problem or not. I guess if you're not actually using SQLite, then this at least passes the version check and so gets you working.

Ralph Bolton
  • 774
  • 7
  • 14
  • The approach still only gets you to version 3.8, released in July 2015. It also doesn't work in the AWS Lambda Python container, if you're using that. – Nick K9 Aug 09 '22 at 15:38
16

django 2.2 need sqlite version >= 3.8.3

so the solution is update your sqlite:

  1. download from sqlite3, select source_code version
  2. tar -zxvf sqlite-xxx.tar.gz && cd xx
  3. ./configure && make && make install
  4. mv /usr/bin/sqlite3 /usr/bin/sqlite3.bak
  5. mv xxx/sqlite3 /usr/bin/sqlite3
  6. export LD_LIBRARY_PATH="/usr/local/lib" and write it into ~/.bashrc

test1 :

sqlite3 --version 

should be your version

test2:

$python
>>> import sqlite3
>>> sqlite3.sqlite_version

should be your version

eastonsuo
  • 935
  • 9
  • 11
  • Please specify the full path, I follow the instruction provided by you, after install where is the sqlite3, unable to find runnable sqlite3. Install cmd display below output `Libraries have been installed in: /usr/local/lib` When I run `ls -l` on the above dir below files list out `libsqlite3.a libsqlite3.la libsqlite3.so -> libsqlite3.so.0.8.6 libsqlite3.so.0 -> libsqlite3.so.0.8.6 libsqlite3.so.0.8.6`. Please guide – dinu0101 Apr 06 '20 at 15:42
  • did you do this?:`mv /usr/bin/sqlite3 /usr/bin/sqlite3.bak` – eastonsuo Apr 10 '20 at 10:25
  • Can you explain step 6? What is that doing? And am I running that as a command and then copying it into bashrc? What does the command do, and what does bashrc do? – kloddant Sep 15 '21 at 14:01
14

To check which version of SQLite Python is using:

$ python
Python 3.7.3 (default, Apr 12 2019, 16:23:13) 
>>> import sqlite3
>>> sqlite3.sqlite_version
'3.27.2'

For me the new version of sqlite3 is in /usr/local/bin so I had to recompile Python, telling it to look there:

sudo LD_RUN_PATH=/usr/local/lib ./configure --enable-optimizations
sudo LD_RUN_PATH=/usr/local/lib make altinstall
Mudasir Zahoor
  • 894
  • 6
  • 18
Mark Bailey
  • 1,617
  • 1
  • 7
  • 13
  • 1
    how exactly is this done? i have a python3.7.7 installation and the sqlite version running is 3.7.17. – JCm Mar 27 '20 at 07:37
8

I had the same issue and I struggled with it for a while. For me the best solution was to comment out DATABASES section in settings.py file.

As I don't want to use SQLite database then issue does not exist anymore. Later on you can update DATABASE information with the db that is valid for you.

Wojtek
  • 89
  • 1
  • Same here. SQLite seems to be the default "DBMS" for Django. If you are just setting up your project you can comment the section out as suggested and later on switch to a DBMS of your choice. – Stephan Schielke Apr 10 '20 at 13:15
  • If you are going to use postgresql for the database, this seems like the simplest approach. – vinh Nov 27 '20 at 00:15
7

You will only get make it worse with errors like multilib and other incompatibilities if keeps forcing the installation of sqlite 3.8.3 or higher. Just as @Theo also commented, the best approach is to comment the line #66 on the sqlite3/base.py (file within django) that triggers the method named check_sqlite_version().

This should just be warning that you are using a minor patch instead of raise an Exception (ImproperlyConfigured). You may also replace the raise with a print.

PD: Just make sure to document it!

enter image description here

Jcc.Sanabria
  • 629
  • 1
  • 12
  • 22
  • 1
    That's my preferred solution, since Centos 7 needs specific version of SQLite for some reason, so I just disabled the check. – ruslaniv Sep 04 '21 at 15:18
7

I was having trouble with the above solutions on an Amazon Linux 2 instance and found that what was installed from my various attempts to update were causing version conflicts. Initially I had this:

$ python3 --version
Python 3.7.9
$ python3
>>> import sqlite3
>>> sqlite3.sqlite_version
'3.7.17'
>>> exit()

And sudo yum install sqlite-3.8.11-1.fc21.x86_64.rpm failed to install with this message: failed updated message

I resolved it by the following steps:

sudo yum list | grep sqlite

These two packages were preventing updates due to conflict. grep list sqlite conflict

sudo yum autoremove sqlite-devel To uninstall the extraneous package.

sudo yum install sqlite-3.8.11-1.fc21.x86_64.rpm To update the version.

sudo yum list | grep sqlite

New list of updated sqlite packages: grep list sqlite v2

$ python3
>>> import sqlite3
>>> sqlite3.sqlite_version
'3.8.11'
>>> exit()
k80oshea
  • 89
  • 1
  • 6
3

After few hours of searching I solved it using one command inside my virtual environment:

pip install pysqlite3-binary

You can check github here and article(a bit outdated) here.

I also found here that you should then place the following lines of code in your settings.py:

__import__('pysqlite3')
import sys
sys.modules['sqlite3'] = sys.modules.pop('pysqlite3')

but for me it worked without it.

Gregorek
  • 106
  • 4
0

another option is to use atomic repo

wget -O - http://updates.atomicorp.com/installers/atomic |sh
yum install  atomic-sqlite
LD_LIBRARY_PATH='/opt/atomicorp/atomic/root/usr/lib64/' python3
>>> import sqlite3
>>> sqlite3.sqlite_version
'3.8.5'
Stavinsky
  • 323
  • 4
  • 11
0

I answered this question here: ImproperlyConfigured('SQLite 3.8.3 or later is required (found %s).' % Database.sqlite_version)

I solved this issue by upgrading my version of sqlite3 using this command:

cd ~ && wget https://www.sqlite.org/2020/sqlite-autoconf-3320100.tar.gz && tar xvfz sqlite-autoconf-3320100.tar.gz && cd sqlite-autoconf-3320100 && ./configure && make && make install

I am using ElasticBeanstalk for my setup, so I added a .config file to the .ebextensions folder and put this in it:

option_settings:
  aws:elasticbeanstalk:application:environment:
    LD_LIBRARY_PATH: "/usr/local/lib"
commands:
  01_upgrade_sqlite:
    command: "cd ~ && wget https://www.sqlite.org/2020/sqlite-autoconf-3320100.tar.gz && tar xvfz sqlite-autoconf-3320100.tar.gz && cd sqlite-autoconf-3320100 && ./configure && make && make install"

Many thanks to Bejür for adding the LD_LIBRARY_PATH environment variable here in order to get it to work.

kloddant
  • 1,026
  • 12
  • 19
  • I tried it with ec2 micro and failed at ./configure step because no acceptable C compiler found in $PATH – UMR Jan 02 '23 at 09:56
  • @UMR Not sure what's going on with that then. I've since given up on using SQLite in favor of using MySQL for everything instead. I know this did work for me at the time though, but I was using Elastic Beanstalk with Amazon Linux, so maybe your environment is different that mine was. – kloddant Jan 03 '23 at 16:27
0

I make a fixed downgrade Django

pip3 install Django==2.1.*
Sajibe Kanti
  • 181
  • 1
  • 9
0

Another hacky way to solve it: build from source and replace lib files.

FROM public.ecr.aws/lambda/python:3.9

RUN cd /tmp && \
    curl -L -O https://www.sqlite.org/2023/sqlite-autoconf-3410200.tar.gz && \
    tar -xzf sqlite-autoconf-3410200.tar.gz && \
    cd sqlite-autoconf-3410200 && \
    ./configure && \
    make -j$(nproc) && \
    make install && \
    cp /usr/local/lib/libsqlite3.so /var/lang/lib/libsqlite3.so && \
    cp /usr/local/lib/libsqlite3.so.0 /var/lang/lib/libsqlite3.so.0 && \
    cp /usr/local/lib/libsqlite3.so.0.8.6 /var/lang/lib/libsqlite3.so.0.8.6 && \
    cp /usr/local/lib/libsqlite3.so.0 /usr/lib64/libsqlite3.so.0 && \
    cp /usr/local/lib/libsqlite3.so.0.8.6 /usr/lib64/libsqlite3.so.0.8.6
khamaileon
  • 197
  • 1
  • 5
-1

i had recently same problem My solution was to change source code site-packages\django\db\backends\sqlite3\base.py line around 68 So far no side effects.

def check_sqlite_version(): if Database.sqlite_version_info < (3, 7, 3): raise ImproperlyConfigured('SQLite 3.8.3 or later is required (found %s).' % Database.sqlite_version)

Theo
  • 19
  • 1