title: Django login error: "attempt to write a readonly database"
body: <p>I'm trying to setup Apache(2.4, built from sources)+Django(1.8.12) on CentOS 6, but when i try to login to my site or create user or something else that writes to DB, i get an error:</p>
  
  <blockquote>
    <p>attempt to write a readonly database</p>
  </blockquote>
  
  <p>I already have tried to:</p>
  
  <ul>
  <li>change owner of db file to <strong>apache</strong> user (not works)</li>
  <li>change permissions: 775, 774, 664 give same error as above; 666, 776 give:</li>
  </ul>
  
  <blockquote>
    <p>unable to open database file</p>
  </blockquote>
  
  <ul>
  <li>same actions to whole folder with django project</li>
  </ul>
  
  <p>I followed <a href="https://docs.djangoproject.com/en/1.8/howto/deployment/wsgi/modwsgi/" rel="nofollow">this</a> tutorial.</p>
  
  <p>My httpd.conf (part which i added):</p>
  
  <pre><code>LoadModule wsgi_module modules/mod_wsgi.so
  WSGIScriptAlias / /var/www/project/project/wsgi.py
  WSGIPythonPath /var/www/project:/var/www/env/lib/python3.5/site-packages
  
  &lt;Directory /var/www/project&gt;
  &lt;Files wsgi.py&gt;
  Require all granted
  &lt;/Files&gt;
  &lt;/Directory&gt;
  </code></pre>
  
  <p><code>./manage createsuperuser</code> work correct, user added to DB.</p>
  
  <p>For serving media i use Nginx (all media and static files retrieves correct).</p>
  
  <p><strong>UPD</strong></p>
  
  <p>Full trace back:</p>
  
  <pre><code>Environment:
  
  
  Request Method: POST
  Request URL: http://localhost:8080/accounts/login/
  
  Django Version: 1.8.12
  Python Version: 3.5.1
  Installed Applications:
  ('bootstrap3',
   'django_admin_bootstrapped',
   'django.contrib.admin',
   'django.contrib.auth',
   'django.contrib.contenttypes',
   'django.contrib.sessions',
   'django.contrib.messages',
   'django.contrib.staticfiles',
   'macros',
   'django_ajax',
   'ckeditor',
   'accounts',
   'main',
   'tutor',
   'public_testing',
   'control_testing',
   'debug_toolbar',
   'django_extensions',
   'mmc')
  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',
   'django.middleware.security.SecurityMiddleware',
   'debug_toolbar.middleware.DebugToolbarMiddleware')
  
  
  Traceback:
  File "/var/www/env/lib/python3.5/site-packages/django/core/handlers/base.py" in get_response
    132.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/var/www/env/lib/python3.5/site-packages/django/views/decorators/debug.py" in sensitive_post_parameters_wrapper
    76.             return view(request, *args, **kwargs)
  File "/var/www/env/lib/python3.5/site-packages/django/utils/decorators.py" in _wrapped_view
    110.                     response = view_func(request, *args, **kwargs)
  File "/var/www/env/lib/python3.5/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
    57.         response = view_func(request, *args, **kwargs)
  File "/var/www/env/lib/python3.5/site-packages/django/contrib/auth/views.py" in login
    51.             auth_login(request, form.get_user())
  File "/var/www/env/lib/python3.5/site-packages/django/contrib/auth/__init__.py" in login
    110.         request.session.cycle_key()
  File "/var/www/env/lib/python3.5/site-packages/django/contrib/sessions/backends/base.py" in cycle_key
    285.         self.create()
  File "/var/www/env/lib/python3.5/site-packages/django/contrib/sessions/backends/db.py" in create
    41.                 self.save(must_create=True)
  File "/var/www/env/lib/python3.5/site-packages/django/contrib/sessions/backends/db.py" in save
    65.                 obj.save(force_insert=must_create, using=using)
  File "/var/www/env/lib/python3.5/site-packages/django/db/models/base.py" in save
    734.                        force_update=force_update, update_fields=update_fields)
  File "/var/www/env/lib/python3.5/site-packages/django/db/models/base.py" in save_base
    762.             updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
  File "/var/www/env/lib/python3.5/site-packages/django/db/models/base.py" in _save_table
    846.             result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
  File "/var/www/env/lib/python3.5/site-packages/django/db/models/base.py" in _do_insert
    885.                                using=using, raw=raw)
  File "/var/www/env/lib/python3.5/site-packages/django/db/models/manager.py" in manager_method
    127.                 return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/var/www/env/lib/python3.5/site-packages/django/db/models/query.py" in _insert
    920.         return query.get_compiler(using=using).execute_sql(return_id)
  File "/var/www/env/lib/python3.5/site-packages/django/db/models/sql/compiler.py" in execute_sql
    974.                 cursor.execute(sql, params)
  File "/var/www/env/lib/python3.5/site-packages/debug_toolbar/panels/sql/tracking.py" in execute
    159.         return self._record(self.cursor.execute, sql, params)
  File "/var/www/env/lib/python3.5/site-packages/debug_toolbar/panels/sql/tracking.py" in _record
    101.             return method(sql, params)
  File "/var/www/env/lib/python3.5/site-packages/django/db/backends/utils.py" in execute
    79.             return super(CursorDebugWrapper, self).execute(sql, params)
  File "/var/www/env/lib/python3.5/site-packages/django/db/backends/utils.py" in execute
    64.                 return self.cursor.execute(sql, params)
  File "/var/www/env/lib/python3.5/site-packages/django/db/utils.py" in __exit__
    98.                 six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/var/www/env/lib/python3.5/site-packages/django/utils/six.py" in reraise
    685.             raise value.with_traceback(tb)
  File "/var/www/env/lib/python3.5/site-packages/django/db/backends/utils.py" in execute
    64.                 return self.cursor.execute(sql, params)
  File "/var/www/env/lib/python3.5/site-packages/django/db/backends/sqlite3/base.py" in execute
    318.         return Database.Cursor.execute(self, query, params)
  
  Exception Type: OperationalError at /accounts/login/
  Exception Value: attempt to write a readonly database
  </code></pre>
  
  <p><strong>UPD 2</strong></p>
  
  <p><code>/tmp</code> permissions:</p>
  
  <pre><code>drwxrwxrwt   6 root root  4096 Apr 22 10:06 tmp
  </code></pre>
  
  <p>settings.py DATABASES:</p>
  
  <pre><code>DATABASES = {
      'default': {
          'ENGINE': 'django.db.backends.sqlite3',
          'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
      }
  }
  </code></pre>
  
  <p>DATABASES section from error page:</p>
  
  <pre><code>DATABASES   {'default': {'ATOMIC_REQUESTS': False,
               'AUTOCOMMIT': True,
               'CONN_MAX_AGE': 0,
               'ENGINE': 'django.db.backends.sqlite3',
               'HOST': '',
               'NAME': '/var/www/project/db.sqlite3',
               'OPTIONS': {},
               'PASSWORD': '********************',
               'PORT': '',
               'TEST': {'CHARSET': None,
                        'COLLATION': None,
                        'MIRROR': None,
                        'NAME': None},
               'TIME_ZONE': 'UTC',
               'USER': ''}}
  </code></pre>