Unable to open database file when django-admin syncdb

Asked by weihua

Hi,All
   Can anyone help me on following issue? when I run the command and syncdb, following error is reported:

PYTHONPATH=/opt/graphite/webapp django-admin syncdb --settings=graphite.settings

/opt/graphite/webapp/graphite/settings.py:237: UserWarning: SECRET_KEY is set to an unsafe default. This should be set in local_settings.py for better security
  warn('SECRET_KEY is set to an unsafe default. This should be set in local_settings.py for better security')
Traceback (most recent call last):
  File "/usr/bin/django-admin", line 5, in <module>
    management.execute_from_command_line()
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 392, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 242, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 285, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 415, in handle
    return self.handle_noargs(**options)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/syncdb.py", line 57, in handle_noargs
    cursor = connection.cursor()
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/__init__.py", line 162, in cursor
    cursor = util.CursorWrapper(self._cursor(), self)
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/__init__.py", line 132, in _cursor
    self.ensure_connection()
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/__init__.py", line 127, in ensure_connection
    self.connect()
  File "/usr/local/lib/python2.7/dist-packages/django/db/utils.py", line 99, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/__init__.py", line 127, in ensure_connection
    self.connect()
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/__init__.py", line 115, in connect
    self.connection = self.get_new_connection(conn_params)
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/sqlite3/base.py", line 346, in get_new_connection
    conn = Database.connect(**conn_params)
django.db.utils.OperationalError: unable to open database file

How to solve this open database issue?

Thanks,
Weihua

Question information

Language:
English Edit question
Status:
Solved
For:
Graphite Edit question
Assignee:
No assignee Edit question
Solved by:
weihua
Solved:
Last query:
Last reply:
Revision history for this message
Jason Dixon (jason-dixongroup) said :
#1

Need more information. Are you installing new or upgrading? Which version? What type of database are you using? Have you read http://graphite.readthedocs.org/en/0.9.14/config-database-setup.html? Have you configured DATABASES in your local_settings.py?

P.S. You also need to set SECRET_KEY to a unique string in local_settings.py as hinted in your output, but it shouldn't have any impact on this issue.

Revision history for this message
weihua (weihua-liang) said :
#2

Hi, Jason,
  Thanks for you reply, I am installing new with Django-1.6.4, graphite-web-0.9.9.
  And my database configure in local_settings.py is as follows:

 DATABASES = {
    'default': {
        'NAME': '/opt/graphite/storage/graphite.db',
        'ENGINE': 'django.db.backends.sqlite3',
        'USER': '',
        'PASSWORD': '',
        'HOST': '',
        'PORT': ''
    }
}

Thanks,
Weihua

Revision history for this message
Jason Dixon (jason-dixongroup) said :
#3

0.9.9 is ancient and completely unsupported. You need to use something modern, either 0.9.14 or a branch (0.9.x or master).

Revision history for this message
weihua (weihua-liang) said :
#4

Hi, Jason,
   Sorry for my previous reply, actually my graphit-web version is 0.10.0

/opt/graphite/webapp/
         ./content
         ./graphite
         ./graphite_web-0.10.0_alpha-py2.7.egg-info

Revision history for this message
Denis Zhdanov (deniszhdanov) said :
#5

You need to create directory for db file explicitly and check that your web server have enough rights to write to that file.
Something like
sudo mkdir -p /opt/graphite/storage/ && sudo chown nobody:nobody /opt/graphite/storage/

Please replace "nobody" with your Apache user - it's 'nobody' for Redhat-based linux and 'www-data' for Ubuntu, for ex.
You can run something like
ps -ef | grep httpd | grep -v `whoami` | grep -v root | head -n1 | awk '{print $1}'
to find out under which user Apache workers run.

Revision history for this message
weihua (weihua-liang) said :
#6

Denis,
   Thanks a lot for your help, I check my storage_dir, it is already www-data user.

    I re-check the graphite document, in it the cmd is:
           PYTHONPATH=/opt/graphite/webapp django-admin.py syncdb --settings=graphite.settings
    But I used before is
           PYTHONPATH=/opt/graphite/webapp django-admin syncdb --settings=graphite.settings

    I am not sure the different between using binary and *.py directly, but now that error disappeared, and the graphite.db is created in STORAGE_DIR!

        sudo PYTHONPATH=/opt/graphite/webapp django-admin.py syncdb --settings=graphite.settings
       Creating tables ...
       Installing custom SQL ...
       Installing indexes ...
       Installed 0 object(s) from 0 fixture(s)