djangodjango-admindjango-permissionsdjango-wsgi

Django::OperationalError at /admin/login/ unable to open database file


I know there's already a same question, i too tried the solutions given their but it dint work for me hence i am writing my own question. Hii all, i am deploying django server using apache2 server and when i tried my host Ip address it works fine as it displays it Worked page, it works for IPADRESS/admin also but after filling in the credentials and hit on enter will produce this error

***OperationalError at /admin/login/
unable to open database file***

and my error looks like

Environment:


Request Method: POST
Request URL: http://192.168.1.105/admin/login/?next=/admin/

Django Version: 1.7.4
Python Version: 2.7.6
Installed Applications:
('django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'managementdashboard')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware')


Traceback:
File "/var/www/dashboardapp/env/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  111.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/var/www/dashboardapp/env/lib/python2.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
  52.         response = view_func(request, *args, **kwargs)
File "/var/www/dashboardapp/env/lib/python2.7/site-packages/django/contrib/admin/sites.py" in login
  361.         return login(request, **defaults)
File "/var/www/dashboardapp/env/lib/python2.7/site-packages/django/views/decorators/debug.py" in sensitive_post_parameters_wrapper
  76.             return view(request, *args, **kwargs)
File "/var/www/dashboardapp/env/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view
  105.                     response = view_func(request, *args, **kwargs)
File "/var/www/dashboardapp/env/lib/python2.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
  52.         response = view_func(request, *args, **kwargs)
File "/var/www/dashboardapp/env/lib/python2.7/site-packages/django/contrib/auth/views.py" in login
  44.             auth_login(request, form.get_user())
File "/var/www/dashboardapp/env/lib/python2.7/site-packages/django/contrib/auth/__init__.py" in login
  96.         request.session.cycle_key()
File "/var/www/dashboardapp/env/lib/python2.7/site-packages/django/contrib/sessions/backends/base.py" in cycle_key
  279.         self.create()
File "/var/www/dashboardapp/env/lib/python2.7/site-packages/django/contrib/sessions/backends/db.py" in create
  41.                 self.save(must_create=True)
File "/var/www/dashboardapp/env/lib/python2.7/site-packages/django/contrib/sessions/backends/db.py" in save
  64.                 obj.save(force_insert=must_create, using=using)
File "/var/www/dashboardapp/env/lib/python2.7/site-packages/django/db/models/base.py" in save
  589.                        force_update=force_update, update_fields=update_fields)
File "/var/www/dashboardapp/env/lib/python2.7/site-packages/django/db/models/base.py" in save_base
  617.             updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
File "/var/www/dashboardapp/env/lib/python2.7/site-packages/django/db/models/base.py" in _save_table
  698.             result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
File "/var/www/dashboardapp/env/lib/python2.7/site-packages/django/db/models/base.py" in _do_insert
  731.                                using=using, raw=raw)
File "/var/www/dashboardapp/env/lib/python2.7/site-packages/django/db/models/manager.py" in manager_method
  92.                 return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/var/www/dashboardapp/env/lib/python2.7/site-packages/django/db/models/query.py" in _insert
  921.         return query.get_compiler(using=using).execute_sql(return_id)
File "/var/www/dashboardapp/env/lib/python2.7/site-packages/django/db/models/sql/compiler.py" in execute_sql
  920.                 cursor.execute(sql, params)
File "/var/www/dashboardapp/env/lib/python2.7/site-packages/django/db/backends/utils.py" in execute
  81.             return super(CursorDebugWrapper, self).execute(sql, params)
File "/var/www/dashboardapp/env/lib/python2.7/site-packages/django/db/backends/utils.py" in execute
  65.                 return self.cursor.execute(sql, params)
File "/var/www/dashboardapp/env/lib/python2.7/site-packages/django/db/utils.py" in __exit__
  94.                 six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/var/www/dashboardapp/env/lib/python2.7/site-packages/django/db/backends/utils.py" in execute
  65.                 return self.cursor.execute(sql, params)
File "/var/www/dashboardapp/env/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py" in execute
  485.         return Database.Cursor.execute(self, query, params)

Exception Type: OperationalError at /admin/login/
Exception Value: unable to open database file

Need help as son as possible, thank you in advance.


Solution

  • Your Apache user does not have the rights needed to write to your database.

    Modify your settings.py so that it shows an absolute path for your database, for example:

    DATABASE_NAME = '/var/www/dashboardapp/whatever/path/db.sqlite3'
    

    Then type the following commands at the Linux prompt to set the correct privileges:

    chown www-data /var/www/dashboardapp/whatever/path/
    chown www-data /var/www/dashboardapp/whatever/path/db.sqlite3