Attempt to write a readonly database Django/Apache2/OperationalError - django

I am working on a Django app and have deployed it to a Ubuntu Server via AWS. Everything that doesn't require a database insert works fine. But when I try to log in (everytime if someone logs in I am saving the 'last login') an OperationalError appears: Attempt to write a readonly.
I already changed the owner of the database and tried also with chmod 666 and chmod 777 but it still doesn't work.
Did someone had the same issue and has solved it?
Kind regards

I found it! Stupid mistake -> I didn't set the permissions on the parent folder of database.

Related

FATAL: password authentication failed for user 'xxx' error when migrating to a postgresql db in RDS

I am trying to migrate to a PostgreSQL db in RDS from Django. The db was set up successfully but when I run python3 manage.py migrate I keep getting the error 'FATAL: password authentication failed for user'. The user name that it mentions is not the master username from RDS which is the same as my USER in settings. I have a .env file with the USER, ENGINE, PASSWORD etc that is being read correctly apart from the fact that it is not referencing the USER. It is referencing the username I use to log onto the computer which I also used when I set up a superuser in the venv.
I have tried logging out from superuser which did nothing. I also tried deactivating the venv which seemed to solve the authentication issue though obviously none of the modules within the venv uploaded so I got errors from that.
I tried changing the password in RDS but it is still trying to connect using the wrong user. I also tried making a new venv but still got the same error. The NAME in settings is set to postgres.
Has anyone else had this issue?

Wagtail superuser unable to log in to CMS

I'm new to Wagtail and django. I've completed the https://learnwagtail.com/wagtail-for-beginners/ course and managed to get my site up and running on Digital ocean, however I'm unable to login to the admin area. I have tried using the superuser credentials that were used locally. I have also tried multiple times to create a new superuser with:
python manage.py createsuperuser
and while the process appears to work successfully in the terminal (I'm logged in via SSH to my DO droplet), I continually receive the 'Your username and password didn't match. Please try again.' message when attempting to log in with the newly created username and password. If I use the shell to check users I can see my newly created user exists. I have also tried using
python manage.py changepassword myusername
to change the password on the previously created superusers, but again, while the process appears to work successfully in the terminal I continue to receive the error message when attempting to log in. Can anyone point me in the right direction as to what I might be missing or doing wrong here? And / or how I might best debug the issue? Thanks in advance!
You might need to set up a Site that matches the domain on which you're accessing your site. In the command line, try this:
import wagtail.core.models.sites
s=Site.objects.last()
s.hostname='yourdomain'
s.site_name='verbose site name'
s.is_default_site=True
s.save()
If you don't already have a site in the database (or just want to add another one), then do s=Site.objects.create() instead of Site.objects.last()place the three properties into thecreate` statement as keywords.
I needed to make sure my manage.py commands were picking up my production settings. So running:
DJANGO_SETTINGS_MODULE=mysite.settings.production ./manage.py createsuperuser
and NOT:
python manage.py createsuperuser was the solution.

Ubuntu + Django + SQLite - attempt to write a readonly database

I'm hosting my Django project with Apache on a Ubuntu 20.04 server with the standard SQLite database. It works but the database seems to be read-only.
When we write to the database we get an OperationalError:
attempt to write a readonly database
I have tried to change the permissions according to the guide below
https://www.digitalocean.com/community/tutorials/how-to-serve-django-applications-with-apache-and-mod_wsgi-on-ubuntu-16-04
I've changed the permissions of the sqlite file to 664 and gave user www-data ownership of the file and the parent folder.
Yet I'm still getting the same error. Any ideas what else could be causing this problem?

Django migrate - django.db.utils.OperationalError: attempt to write a readonly database

I have read the answers to similar (same) questions and the solutions have not worked for me.
I have a django application running with Apache2 webserver, and the user is set to the default www-data. Currently, www-data has full access to the db. This was working fine until couple of commits ago and I'm clueless at exactly what went wrong (Since I didn't touch the database at all during the period). Another thing to note is that makemigrations work perfectly fine, and the database is editable without errors in the django admin console.
Currently, this is my permission settings for the db:
The error message is:
Any help would be appreciated thanks!

Django Lightsail - attempt to write a readonly database

I am trying to deploy my Djago app on AWS Lightsail.
When I try to login/register, I am getting this error:
Attempt to write a readonly database
I have been googling solutions for quite some time and have tried setting different permissions, even giving away all permissions which might be huge security risk, however it still doesn't work.
Could anyone help me.
check that your file is owned by bitnami:bitnami. (I've been having the same exact issue and yours and i havent been able to fix it either)
So, in case someone else has this problem, what should work and what worked for me:
I moved db.sqlite3 file to one folder outside of main project dir.
Then I changed address to this file in settings.py to os.path.join(BASE_DIR, '..', 'db.sqlite3')
Though I feel like it's really a problem of user permissions, but that's above my current skill level.
I found another solution that worked for me.
See: https://github.com/mchesler613/django_adventures/blob/main/deploy_django_aws_bitnami.md
Author goes into detail about the details behind the error.
See "Error: Attempt to write a readonly database"
Change group ownership of the project root directory and the database file to daemon. For example:
$ sudo chgrp daemon project_directory project_directory/database_file
Make the project root directory and the database file writable by the daemon group. For example:
$ sudo chmod g+w project_directory project_directory/database_file
To see if the database error goes away, try reloading the Django app on the browser.
I had the same problem. Changing db.sqlite3 mode to writable doesn't work for me. I can use django shell to add data to db.sqlite3 but from apache2, it doesn't work.
Finally, I changed owner of the directory where db.sqlite3 locates to www-data:www-data, and it worked.