attempt to write a readonly database using URL

Sorry in advance for a newby question. I’ve just set up a test site using the following tutorials


the django project poller tutorial 0 (sorry can only have one link in the post)

On a raspberry pi 4 - running Raspian
Django - v3.0.3
apache2 - Apache/2.4.38 (Raspbian)
python - 3.7.3
Transport is HTTP, SSL is not configured

The issue I’m having is odd, if I access the server via it’s IP address, everything works as expected, no errors, the admin site works etc.

If however, I access the site using a URL instead, I get the below error.
File and directory permissions have been set as per the tutorial and continue to work correctly as long as I use the IP. At this point I’m a bit stumped, any assistance will be gratefully received.


OperationalError at /admin/login/

attempt to write a readonly database

Request Method: POST
Request URL: http://lsapp01.site.com/admin/login/?next=/admin/
Django Version: 3.0.3
Exception Type: OperationalError
Exception Value: attempt to write a readonly database
Exception Location: /var/www/django_app/django_appenv/lib/python3.7/site-packages/django/db/backends/sqlite3/base.py in execute, line 396
Python Executable: /var/www/django_app/django_appenv/bin/python
Python Version: 3.7.3
Python Path: [’/var/www/django_app’, ‘/usr/lib/python37.zip’, ‘/usr/lib/python3.7’, ‘/usr/lib/python3.7/lib-dynload’, ‘/var/www/django_app/django_appenv/lib/python3.7/site-packages’]
Server time: Thu, 13 Feb 2020 04:21:05 +0000

Apache Error log

==> /var/log/apache2/error.log <==
[Thu Feb 13 05:24:47.692996 2020] [wsgi:error] [pid 25870] [remote 10.16.4.236:55697] Internal Server Error: /admin/login/
[Thu Feb 13 05:24:47.693086 2020] [wsgi:error] [pid 25870] [remote 10.16.4.236:55697] Traceback (most recent call last):
[Thu Feb 13 05:24:47.693105 2020] [wsgi:error] [pid 25870] [remote 10.16.4.236:55697]   File "/var/www/django_app/django_appenv/lib/python3.7/site-packages/django/db/backends/utils.py", line 86, in _execute
[Thu Feb 13 05:24:47.693122 2020] [wsgi:error] [pid 25870] [remote 10.16.4.236:55697]     return self.cursor.execute(sql, params)
[Thu Feb 13 05:24:47.693139 2020] [wsgi:error] [pid 25870] [remote 10.16.4.236:55697]   File "/var/www/django_app/django_appenv/lib/python3.7/site-packages/django/db/backends/sqlite3/base.py", line 396, in execute
[Thu Feb 13 05:24:47.693207 2020] [wsgi:error] [pid 25870] [remote 10.16.4.236:55697]     return Database.Cursor.execute(self, query, params)
[Thu Feb 13 05:24:47.693285 2020] [wsgi:error] [pid 25870] [remote 10.16.4.236:55697] sqlite3.OperationalError: attempt to write a readonly database
[Thu Feb 13 05:24:47.693348 2020] [wsgi:error] [pid 25870] [remote 10.16.4.236:55697] 
[Thu Feb 13 05:24:47.693409 2020] [wsgi:error] [pid 25870] [remote 10.16.4.236:55697] The above exception was the direct cause of the following exception:
[Thu Feb 13 05:24:47.693497 2020] [wsgi:error] [pid 25870] [remote 10.16.4.236:55697] 
[Thu Feb 13 05:24:47.693516 2020] [wsgi:error] [pid 25870] [remote 10.16.4.236:55697] Traceback (most recent call last):
[Thu Feb 13 05:24:47.693553 2020] [wsgi:error] [pid 25870] [remote 10.16.4.236:55697]   File "/var/www/django_app/django_appenv/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner
[Thu Feb 13 05:24:47.693571 2020] [wsgi:error] [pid 25870] [remote 10.16.4.236:55697]     response = get_response(request)
[Thu Feb 13 05:24:47.693587 2020] [wsgi:error] [pid 25870] [remote 10.16.4.236:55697]   File "/var/www/django_app/django_appenv/lib/python3.7/site-packages/django/core/handlers/base.py", line 115, in _get_response
[Thu Feb 13 05:24:47.693664 2020] [wsgi:error] [pid 25870] [remote 10.16.4.236:55697]     response = self.process_exception_by_middleware(e, request)
[Thu Feb 13 05:24:47.693679 2020] [wsgi:error] [pid 25870] [remote 10.16.4.236:55697]   File "/var/www/django_app/django_appenv/lib/python3.7/site-packages/django/core/handlers/base.py", line 113, in _get_response
[Thu Feb 13 05:24:47.693717 2020] [wsgi:error] [pid 25870] [remote 10.16.4.236:55697]     response = wrapped_callback(request, *callback_args, **callback_kwargs)
[Thu Feb 13 05:24:47.693736 2020] [wsgi:error] [pid 25870] [remote 10.16.4.236:55697]   File "/var/www/django_app/django_appenv/lib/python3.7/site-packages/django/views/decorators/cache.py", line 44, in _wrapped_view_func
[Thu Feb 13 05:24:47.693788 2020] [wsgi:error] [pid 25870] [remote 10.16.4.236:55697]     response = view_func(request, *args, **kwargs)
[Thu Feb 13 05:24:47.693804 2020] [wsgi:error] [pid 25870] [remote 10.16.4.236:55697]   File "/var/www/django_app/django_appenv/lib/python3.7/site-packages/django/contrib/admin/sites.py", line 407, in login
[Thu Feb 13 05:24:47.693840 2020] [wsgi:error] [pid 25870] [remote 10.16.4.236:55697]     return LoginView.as_view(**defaults)(request)
[Thu Feb 13 05:24:47.693858 2020] [wsgi:error] [pid 25870] [remote 10.16.4.236:55697]   File "/var/www/django_app/django_appenv/lib/python3.7/site-packages/django/views/generic/base.py", line 71, in view
[Thu Feb 13 05:24:47.693907 2020] [wsgi:error] [pid 25870] [remote 10.16.4.236:55697]     return self.dispatch(request, *args, **kwargs)
[Thu Feb 13 05:24:47.693925 2020] [wsgi:error] [pid 25870] [remote 10.16.4.236:55697]   File "/var/www/django_app/django_appenv/lib/python3.7/site-packages/django/utils/decorators.py", line 43, in _wrapper
[Thu Feb 13 05:24:47.693940 2020] [wsgi:error] [pid 25870] [remote 10.16.4.236:55697]     return bound_method(*args, **kwargs)
[Thu Feb 13 05:24:47.693979 2020] [wsgi:error] [pid 25870] [remote 10.16.4.236:55697]   File "/var/www/django_app/django_appenv/lib/python3.7/site-packages/django/views/decorators/debug.py", line 76, in sensitive_post_parameters_wrapper
[Thu Feb 13 05:24:47.693995 2020] [wsgi:error] [pid 25870] [remote 10.16.4.236:55697]     return view(request, *args, **kwargs)
[Thu Feb 13 05:24:47.694009 2020] [wsgi:error] [pid 25870] [remote 10.16.4.236:55697]   File "/var/www/django_app/django_appenv/lib/python3.7/site-packages/django/utils/decorators.py", line 43, in _wrapper
[Thu Feb 13 05:24:47.694064 2020] [wsgi:error] [pid 25870] [remote 10.16.4.236:55697]     return bound_method(*args, **kwargs)
[Thu Feb 13 05:24:47.694079 2020] [wsgi:error] [pid 25870] [remote 10.16.4.236:55697]   File "/var/www/django_app/django_appenv/lib/python3.7/site-packages/django/utils/decorators.py", line 130, in _wrapped_view
[Thu Feb 13 05:24:47.694145 2020] [wsgi:error] [pid 25870] [remote 10.16.4.236:55697]     response = view_func(request, *args, **kwargs)
[Thu Feb 13 05:24:47.694214 2020] [wsgi:error] [pid 25870] [remote 10.16.4.236:55697]   File "/var/www/django_app/django_appenv/lib/python3.7/site-packages/django/utils/decorators.py", line 43, in _wrapper
[Thu Feb 13 05:24:47.694231 2020] [wsgi:error] [pid 25870] [remote 10.16.4.236:55697]     return bound_method(*args, **kwargs)
[Thu Feb 13 05:24:47.694246 2020] [wsgi:error] [pid 25870] [remote 10.16.4.236:55697]   File "/var/www/django_app/django_appenv/lib/python3.7/site-packages/django/views/decorators/cache.py", line 44, in _wrapped_view_func
[Thu Feb 13 05:24:47.694261 2020] [wsgi:error] [pid 25870] [remote 10.16.4.236:55697]     response = view_func(request, *args, **kwargs)
[Thu Feb 13 05:24:47.694275 2020] [wsgi:error] [pid 25870] [remote 10.16.4.236:55697]   File "/var/www/django_app/django_appenv/lib/python3.7/site-packages/django/contrib/auth/views.py", line 63, in dispatch
[Thu Feb 13 05:24:47.694313 2020] [wsgi:error] [pid 25870] [remote 10.16.4.236:55697]     return super().dispatch(request, *args, **kwargs)
[Thu Feb 13 05:24:47.694327 2020] [wsgi:error] [pid 25870] [remote 10.16.4.236:55697]   File "/var/www/django_app/django_appenv/lib/python3.7/site-packages/django/views/generic/base.py", line 97, in dispatch
[Thu Feb 13 05:24:47.694391 2020] [wsgi:error] [pid 25870] [remote 10.16.4.236:55697]     return handler(request, *args, **kwargs)
[Thu Feb 13 05:24:47.694407 2020] [wsgi:error] [pid 25870] [remote 10.16.4.236:55697]   File "/var/www/django_app/django_appenv/lib/python3.7/site-packages/django/views/generic/edit.py", line 142, in post
[Thu Feb 13 05:24:47.694421 2020] [wsgi:error] [pid 25870] [remote 10.16.4.236:55697]     return self.form_valid(form)
[Thu Feb 13 05:24:47.694458 2020] [wsgi:error] [pid 25870] [remote 10.16.4.236:55697]   File "/var/www/django_app/django_appenv/lib/python3.7/site-packages/django/contrib/auth/views.py", line 92, in form_valid
[Thu Feb 13 05:24:47.694474 2020] [wsgi:error] [pid 25870] [remote 10.16.4.236:55697]     auth_login(self.request, form.get_user())
[Thu Feb 13 05:24:47.694522 2020] [wsgi:error] [pid 25870] [remote 10.16.4.236:55697]   File "/var/www/django_app/django_appenv/lib/python3.7/site-packages/django/contrib/auth/__init__.py", line 107, in login
[Thu Feb 13 05:24:47.694540 2020] [wsgi:error] [pid 25870] [remote 10.16.4.236:55697]     request.session.cycle_key()
[Thu Feb 13 05:24:47.694555 2020] [wsgi:error] [pid 25870] [remote 10.16.4.236:55697]   File "/var/www/django_app/django_appenv/lib/python3.7/site-packages/django/contrib/sessions/backends/base.py", line 310, in cycle_key
[Thu Feb 13 05:24:47.694591 2020] [wsgi:error] [pid 25870] [remote 10.16.4.236:55697]     self.create()
[Thu Feb 13 05:24:47.694607 2020] [wsgi:error] [pid 25870] [remote 10.16.4.236:55697]   File "/var/www/django_app/django_appenv/lib/python3.7/site-packages/django/contrib/sessions/backends/db.py", line 55, in create
[Thu Feb 13 05:24:47.694621 2020] [wsgi:error] [pid 25870] [remote 10.16.4.236:55697]     self.save(must_create=True)
[Thu Feb 13 05:24:47.694671 2020] [wsgi:error] [pid 25870] [remote 10.16.4.236:55697]   File "/var/www/django_app/django_appenv/lib/python3.7/site-packages/django/contrib/sessions/backends/db.py", line 87, in save
[Thu Feb 13 05:24:47.694688 2020] [wsgi:error] [pid 25870] [remote 10.16.4.236:55697]     obj.save(force_insert=must_create, force_update=not must_create, using=using)
[Thu Feb 13 05:24:47.694702 2020] [wsgi:error] [pid 25870] [remote 10.16.4.236:55697]   File "/var/www/django_app/django_appenv/lib/python3.7/site-packages/django/db/models/base.py", line 746, in save
[Thu Feb 13 05:24:47.694717 2020] [wsgi:error] [pid 25870] [remote 10.16.4.236:55697]     force_update=force_update, update_fields=update_fields)
[Thu Feb 13 05:24:47.694753 2020] [wsgi:error] [pid 25870] [remote 10.16.4.236:55697]   File "/var/www/django_app/django_appenv/lib/python3.7/site-packages/django/db/models/base.py", line 784, in save_base
[Thu Feb 13 05:24:47.694824 2020] [wsgi:error] [pid 25870] [remote 10.16.4.236:55697]     force_update, using, update_fields,
[Thu Feb 13 05:24:47.694840 2020] [wsgi:error] [pid 25870] [remote 10.16.4.236:55697]   File "/var/www/django_app/django_appenv/lib/python3.7/site-packages/django/db/models/base.py", line 887, in _save_table
[Thu Feb 13 05:24:47.694871 2020] [wsgi:error] [pid 25870] [remote 10.16.4.236:55697]     results = self._do_insert(cls._base_manager, using, fields, returning_fields, raw)
[Thu Feb 13 05:24:47.694886 2020] [wsgi:error] [pid 25870] [remote 10.16.4.236:55697]   File "/var/www/django_app/django_appenv/lib/python3.7/site-packages/django/db/models/base.py", line 926, in _do_insert
[Thu Feb 13 05:24:47.694918 2020] [wsgi:error] [pid 25870] [remote 10.16.4.236:55697]     using=using, raw=raw,
[Thu Feb 13 05:24:47.694932 2020] [wsgi:error] [pid 25870] [remote 10.16.4.236:55697]   File "/var/www/django_app/django_appenv/lib/python3.7/site-packages/django/db/models/manager.py", line 82, in manager_method
[Thu Feb 13 05:24:47.694959 2020] [wsgi:error] [pid 25870] [remote 10.16.4.236:55697]     return getattr(self.get_queryset(), name)(*args, **kwargs)
[Thu Feb 13 05:24:47.694988 2020] [wsgi:error] [pid 25870] [remote 10.16.4.236:55697]   File "/var/www/django_app/django_appenv/lib/python3.7/site-packages/django/db/models/query.py", line 1204, in _insert
[Thu Feb 13 05:24:47.695003 2020] [wsgi:error] [pid 25870] [remote 10.16.4.236:55697]     return query.get_compiler(using=using).execute_sql(returning_fields)
[Thu Feb 13 05:24:47.695034 2020] [wsgi:error] [pid 25870] [remote 10.16.4.236:55697]   File "/var/www/django_app/django_appenv/lib/python3.7/site-packages/django/db/models/sql/compiler.py", line 1384, in execute_sql
[Thu Feb 13 05:24:47.695049 2020] [wsgi:error] [pid 25870] [remote 10.16.4.236:55697]     cursor.execute(sql, params)
[Thu Feb 13 05:24:47.695079 2020] [wsgi:error] [pid 25870] [remote 10.16.4.236:55697]   File "/var/www/django_app/django_appenv/lib/python3.7/site-packages/django/db/backends/utils.py", line 100, in execute
[Thu Feb 13 05:24:47.695094 2020] [wsgi:error] [pid 25870] [remote 10.16.4.236:55697]     return super().execute(sql, params)
[Thu Feb 13 05:24:47.695123 2020] [wsgi:error] [pid 25870] [remote 10.16.4.236:55697]   File "/var/www/django_app/django_appenv/lib/python3.7/site-packages/django/db/backends/utils.py", line 68, in execute
[Thu Feb 13 05:24:47.695139 2020] [wsgi:error] [pid 25870] [remote 10.16.4.236:55697]     return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
[Thu Feb 13 05:24:47.695168 2020] [wsgi:error] [pid 25870] [remote 10.16.4.236:55697]   File "/var/www/django_app/django_appenv/lib/python3.7/site-packages/django/db/backends/utils.py", line 77, in _execute_with_wrappers
[Thu Feb 13 05:24:47.695183 2020] [wsgi:error] [pid 25870] [remote 10.16.4.236:55697]     return executor(sql, params, many, context)
[Thu Feb 13 05:24:47.695220 2020] [wsgi:error] [pid 25870] [remote 10.16.4.236:55697]   File "/var/www/django_app/django_appenv/lib/python3.7/site-packages/django/db/backends/utils.py", line 86, in _execute
[Thu Feb 13 05:24:47.695235 2020] [wsgi:error] [pid 25870] [remote 10.16.4.236:55697]     return self.cursor.execute(sql, params)
[Thu Feb 13 05:24:47.695264 2020] [wsgi:error] [pid 25870] [remote 10.16.4.236:55697]   File "/var/www/django_app/django_appenv/lib/python3.7/site-packages/django/db/utils.py", line 90, in __exit__
[Thu Feb 13 05:24:47.695279 2020] [wsgi:error] [pid 25870] [remote 10.16.4.236:55697]     raise dj_exc_value.with_traceback(traceback) from exc_value
[Thu Feb 13 05:24:47.695307 2020] [wsgi:error] [pid 25870] [remote 10.16.4.236:55697]   File "/var/www/django_app/django_appenv/lib/python3.7/site-packages/django/db/backends/utils.py", line 86, in _execute
[Thu Feb 13 05:24:47.695322 2020] [wsgi:error] [pid 25870] [remote 10.16.4.236:55697]     return self.cursor.execute(sql, params)
[Thu Feb 13 05:24:47.695356 2020] [wsgi:error] [pid 25870] [remote 10.16.4.236:55697]   File "/var/www/django_app/django_appenv/lib/python3.7/site-packages/django/db/backends/sqlite3/base.py", line 396, in execute
[Thu Feb 13 05:24:47.695391 2020] [wsgi:error] [pid 25870] [remote 10.16.4.236:55697]     return Database.Cursor.execute(self, query, params)
[Thu Feb 13 05:24:47.695428 2020] [wsgi:error] [pid 25870] [remote 10.16.4.236:55697] django.db.utils.OperationalError: attempt to write a readonly database

==> /var/log/apache2/access.log <==
10.16.4.236 - - [13/Feb/2020:16:24:47 +1100] "POST /admin/login/?next=/admin/ HTTP/1.1" 500 215461 "http://lsapp01.syd01.silvacloud.net.au/admin/login/?next=/admin/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.87 Safari/537.36"