Django :: OperationalError at / admin / login /无法打开数据库文件

时间:2015-02-25 10:34:30

标签: django django-admin django-permissions django-wsgi

我知道那里已经有了一个同样的问题,我也尝试过给出他们的解决方案但是 dint work 对我来说因此我正在写自己的问题。 Hii all,我正在使用apache2服务器部署django服务器,当我尝试我的主机IP地址时,它工作正常,因为它显示 it Worked 页面,它适用于 IPADRESS / admin 但填写完凭证并点击确认后会产生此错误

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

我的错误看起来像是

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

尽可能帮助儿子,谢谢你。

2 个答案:

答案 0 :(得分:5)

您的Apache用户没有写入数据库所需的权限。

修改您的settings.py,使其显示数据库的绝对路径,例如:

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

然后在Linux提示符下键入以下命令以设置正确的权限:

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

答案 1 :(得分:0)

转到您的项目目录,只需与IIS用户共享权限即可,如果已部署在IIS Windows服务器上,则应该完成此任务