1

I have a Django web app installed in IIS 10 and I applied some models into the db.sqlite3 but when I tried to log into the django/admin/login I encountered the error: OperationalError at /admin/login/attempt to write a readonly database.

I have found solutions to this problem in sqlite3 error attempt to write a read only database, Django admin backend, attempt-to-write-a-readonly-database-django and all of them mention to change the permissions of the database folder. I changed the permissions of that folder by deselecting the option Read-only (Only applies to files in folder) but it seems that when I hit the Apply button it does not make any change because I check again the folder and it has the Read-only option activated.

Questions:

  1. Is there any way to change this permission by any command terminal in powershell?
  2. Do I have to do any extra step in IIS to make the db.sqlite3 working?

Any help is welcome!

abautista
  • 2,410
  • 5
  • 41
  • 72

2 Answers2

4

I Have this problem with IIS and solved with this way:

first go to this link (Watch from 10:30 to 11:12 ) and create Group User .

Then follow numbers in below image:

enter image description here And restart web service must be done.

If after this you get “Unable to open the database file” error you can open this link and see the fourth solution from @Arkady.

:

.--------------------------------------------------------------------------------

@Arkady say: I had a problem opening Sqlite database in IIS

(0x80004005): unable to open database file unable to open database file

what helped me to solve the problem is changing the "Identity" of the application pool to "LocalSystem"

Application Pools -> DefaultAppPool (or another pool you are working with) -> Advanced Settings -> Identity -> LocalSystem

Hopefully it will save someone time...

.-----------------------------------------------------------------------------------

Community
  • 1
  • 1
henrry
  • 486
  • 6
  • 25
3

For your first question, you can use icacls. Please see the post How to grant permission to users for a directory using command line in Windows?

For your second question, you need to provide the write permission on your database. A secure way for doing this is to use the same user name that you use to log into your machine in your Django administration tool. In this way, if you are the administrator of the web app then you are the only user who can get direct access to the db.sqlite3.

Granting other users to have writing permissions in the db.sqlite3 is not recommended because this database usually stores data that is necessary for the correct function of your web app, i.e., Django models are stored in this database and if they are altered then your web app may stop working correctly .

Follow these steps to solve the Django login error attempt to write a readonly database in IIS:

  1. Create super user in your Django web app with:

    python manage.py createsuperuser
    

    The user name must be the same as the user name that you use to log in into your machine. The password is not necessarily to be the same as the password of the user name that you use to log in into your machine.

  2. Search for your db.sqlite3 and do a right click and then hit on the Properties option.

  3. Select the Security tab and you will see the group or user names with their respective privileges. Normally, SYSTEM and Administrators have all the privileges checked, but unless you are one of these you will have to modify the Users group because in this group is the user name that you use to log in into your machine.
  4. Select the Users group and verify in the Permissions for Users box that the Write option does not have a checked mark in the Allow column.
  5. Click on the Edit option, select the Users group and select the Write option in the Permissions for Users box. Click Apply then OK, then again Apply and OK.
  6. Go back to your Django administration login page, type the user name that you created as super user.
abautista
  • 2,410
  • 5
  • 41
  • 72
Astik Anand
  • 12,757
  • 9
  • 41
  • 51