0

I'm trying to follow the tutorial, but facing the below error.
The error was disappeared when I changed the permissions of the parent folder and the db.sqlite3 file to 777, but that's not the good idea. What's the alternative?

Reference:
https://docs.djangoproject.com/en/3.2/intro/tutorial02/

Error:

OperationalError at /admin/logout/
attempt to write a readonly database
Request Method: GET
Request URL:    http://x.x.x.x/admin/logout/
Django Version: 3.1.6
Exception Type: OperationalError
Exception Value:    
attempt to write a readonly database
Exception Location: /opt/bitnami/python/lib/python3.8/site-packages/django/db/backends/sqlite3/base.py, line 413, in execute
Python Executable:  /usr/bin/python3
Python Version: 3.8.7
Python Path:    
['/opt/bitnami/python/lib/python38.zip',
 '/opt/bitnami/python/lib/python3.8',
 '/opt/bitnami/python/lib/python3.8/lib-dynload',
 '/opt/bitnami/python/lib/python3.8/site-packages',
 '/opt/bitnami/python/lib/python3.8/site-packages/setuptools-46.4.0-py3.8.egg',
 '/opt/bitnami/python/lib/python3.8/site-packages/pip-20.3.4-py3.8.egg',
 '/opt/bitnami/python/lib/python3.8/site-packages/virtualenv-20.4.2-py3.8.egg',
 '/opt/bitnami/python/lib/python3.8/site-packages/six-1.15.0-py3.8.egg',
 '/opt/bitnami/python/lib/python3.8/site-packages/filelock-3.0.12-py3.8.egg',
 '/opt/bitnami/python/lib/python3.8/site-packages/distlib-0.3.1-py3.8.egg',
 '/opt/bitnami/python/lib/python3.8/site-packages/appdirs-1.4.4-py3.8.egg',
 '/opt/bitnami/apps/django/django_projects/tutorial']
Server time:    Thu, 29 Apr 2021 06:17:14 +0000

Folder and file status:

bitnami@ip---:/opt/bitnami/apps/django/django_projects$ ls -al
total 12
drwxrwxr-x 3 root     root     4096 Apr 22 05:09 .
drwxr-xr-x 3 root     root     4096 Apr 22 05:09 ..
drwxrwxr-x 6 www-data www-data 4096 Apr 29 06:16 tutorial
bitnami@ip---:/opt/bitnami/apps/django/django_projects$ ls -al tutorial/
total 168
drwxrwxr-x 6 www-data www-data   4096 Apr 29 06:16 .
drwxrwxr-x 3 root     root       4096 Apr 22 05:09 ..
drwxr-xr-x 2 www-data www-data   4096 Apr 22 05:45 conf
-rwxrwxrwx 1 www-data www-data 143360 Apr 29 06:16 db.sqlite3
drwxr-xr-x 4 www-data www-data   4096 Apr 28 16:08 hello_world
-rwxr-xr-x 1 www-data www-data    664 Apr 22 05:08 manage.py
drwxr-xr-x 4 www-data www-data   4096 Apr 28 18:04 polls
drwxr-xr-x 3 www-data www-data   4096 Apr 28 16:12 tutorial
Rina K
  • 1
  • 1
  • The error show you are trying to write to readonly database it is because of you don't have permission to write you have permission to readonly – Ankit Tiwari Apr 29 '21 at 06:54
  • you can check this post for more information to change permission on linux https://stackoverflow.com/a/21055324/14457833 – Ankit Tiwari Apr 29 '21 at 06:57
  • Does this answer your question? [Attempt to write a readonly database - Django w/ SELinux error](https://stackoverflow.com/questions/21054245/attempt-to-write-a-readonly-database-django-w-selinux-error) – Ankit Tiwari Apr 29 '21 at 06:57
  • @AnkitTiwari I understood this is the permission issue, I was trying to use the command to turn off the selinux but command not found error was comming. I'm using aws django, how can I control the selinux? $sudo setsebool -P httpd_unified 1 sudo: setsebool: command not found $ sestatus -bash: sestatus: command not found $ setenforce 0 – Rina K Apr 29 '21 at 12:47
  • Hello @Rina K did you tried the commands of this post https://stackoverflow.com/questions/21054245/attempt-to-write-a-readonly-database-django-w-selinux-error/21055324#21055324 – Ankit Tiwari Apr 29 '21 at 15:27
  • @AnkitTiwari Granting ownership of db.sqlite3 and its parent directory was done and regarding the SELinux command, it won't be available since it's disabled by default (aws lightsail). Is there any other option that I could try more? – Rina K Apr 29 '21 at 16:20

1 Answers1

0

Updated the solution by myself :

$ sudo chown daemon:daemon /opt/bitnami/apps/django/django_projects
$ sudo chown daemon:daemon /opt/bitnami/apps/django/django_projects/db.sqlite3
$ sudo chmod 775 /opt/bitnami/apps/django/django_projects
$ sudo chown 775 /opt/bitnami/apps/django/django_projects/db.sqlite3

Platform : AWS Lightsail
Finally it works!

Rina K
  • 1
  • 1