Django is “unable to open database file”

后端 未结 7 1229
栀梦
栀梦 2020-12-15 02:58

after running \"python manage.py syncdb\" i gett an error saying \"unable to open database file\".

here is the important part from my settings.py:

DA         


        
相关标签:
7条回答
  • 2020-12-15 03:21

    Solution from NewbieMistakes

    Make sure Apache can also write to the parent directory of the database. SQLite needs to be able to write to this directory.

    Make sure each folder of your database file's full path does not start with number, eg. /www/4myweb/db (observed on Windows 2000).

    If DATABASE_NAME is set to something like '/Users/yourname/Sites/mydjangoproject/db/db', make sure you've created the 'db' directory first.

    Make sure your /tmp directory is world-writable (an unlikely cause as other thing on your system will also not work). ls /tmp -ald should produce drwxrwxrwt ....

    Make sure the path to the database specified in settings.py is a full path.

    0 讨论(0)
  • 2020-12-15 03:25

    I solved the error by changing the DATABASE_NAME to an absolute path: /var/www/apps/apps.db.

    On a windows machine, backslash should be escaped like: C:\\path\\to\\database\\database_name.db.

    0 讨论(0)
  • 2020-12-15 03:26

    Just rename the database file with .sqlite3 extension, that works with me.

    0 讨论(0)
  • 2020-12-15 03:27

    To change the permission of parent directory, you can use below set of commands:

    check apache process for apache v2:

    ps -ef | grep apache | grep -v grep
    

    the user/group is www-data

    chgrp www-data /path/to/mydir
    chmod g+w /path/to/mydir
    

    Ref: https://askubuntu.com/questions/58725/how-do-we-know-that-a-directory-is-apache-writable

    0 讨论(0)
  • 2020-12-15 03:37

    DATABASE_NAME is deprecated. You must use the currently supported format. i.e.

    DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': 'C:/ispdb.sqlite',
        'USER': '',
        'PASSWORD': '',
        'HOST': '',
        'PORT': ''
    
    }
    

    And also see other settings which are deprecated from the django website.:))

    0 讨论(0)
  • 2020-12-15 03:42

    Well, I answered it on this question. http://goo.gl/KAuXz

    I faced exactly same issue. Here is my setting which worked.

    'ENGINE': 'django.db.backends.sqlite3', 
    'NAME': '/home/neo/django/db/data.sqlite3'
    

    Other setting in case of sqlite3 will be same/default.

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