django.db.utils.OperationalError: unable to open database file

后端 未结 8 509

When I run

python manage.py runserver

I get this error

File \"/usr/local/lib/python2.7/dist-packages/Django-1.10.1-py2.7.egg/django

相关标签:
8条回答
  • 2020-12-10 16:48

    Basically there are two answers, either user which running server don't have rights to open database file. You can try to fix this by:

    sudo chown $(whoami):$(whoami) /path/to/dir/db/db.sqlite3
    

    Or you don't have this file, you can create it by applying migrate command:

    ./manage.py migrate
    
    0 讨论(0)
  • 2020-12-10 16:49

    I had the same problem, just solved it. Make sure www-data (or whatever daemon running your web server) has access to both the db.sqlite3 file, and also the path to it. So:

    sudo chown :www-data <project_folder>/
    sudo chown :www-data <project_folder>/db.sqlite3
    sudo chmod 664 <project_folder>/db.sqlite3
    
    0 讨论(0)
  • 2020-12-10 16:56

    Suffering for a while from the same issue and I believe I have found a solution, finally!

    sudo python manage.py runserver
    

    and that did the trick for me.

    My permissions were telling me that everything is how it should be. Regardless, I still had to type in sudo at the beginning of the command at the terminal.

    0 讨论(0)
  • 2020-12-10 17:00

    If you are experiencing this problem on AWS EC2 node and using apache, to solve the problem I had to:

    chown -R apache:apache project_folder
    
    0 讨论(0)
  • 2020-12-10 17:00

    @whinytween96 : I have seen this problem occur more when sudo is used to run some commands and not for others. You need to be consistent with the usage of sudo to fix this problem. I had the DB issue and I fixed it by running the command again with sudo prefixed.

    i.e.

    1. sudo python manage.py runserver
    2. sudo python manage.py makemigrations
    3. sudo python manage.py migrate

    fixed the problem for me.

    0 讨论(0)
  • 2020-12-10 17:06

    For me, the issue was that I had two settings files; one for production and one for development. In my manage.py, I'd specified the deployment settings file and forgotten to add manage.py to my .gitignore, so when I ran the project locally it failed when trying to find the production database.

    0 讨论(0)
提交回复
热议问题