0

I am getting the following error when I try to run a Django site in production:

OperationalError at / unable to open database file

The strangest part is that it worked for a few page reloads and even clicks on different navigation links. Then, it worked every other time or so. At the end, it stopped working all together. This behavior is very puzzling.

Here is the relevant piece from settings.py

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

I have done chmod 777 db.sqlite as well as chmod o+w . within the directory where db.sqlite3 is located. It did not help.

How could I fix this? I am using a basic EC2 instance with Linux and Apache 2.4

Edit:

I have just duplicated the entire directory of the project using cp project project1 and then did mv project1 project. This made the site work for a few clicks, but then the error started creeping in again. Could this be a server issue?

MadPhysicist
  • 5,401
  • 11
  • 42
  • 107

2 Answers2

1

I fixed it by running the following two commands from within the directory where the DB file was stored:

sudo chown apache:www db.sqlite3

sudo chown apache:www .

This did it for me for AWS EC2 with Amazon Linux (CentOS)

MadPhysicist
  • 5,401
  • 11
  • 42
  • 107
-1

You set the name of your DB to the full path. Don't do this. Just say 'NAME': 'db.sqlite3'

Mihai Zamfir
  • 2,167
  • 4
  • 22
  • 37