Sunday, April 21, 2019

Django Sqlite3 database with write access

To use the Sqlite3 database with write permissions, the following setup is needed.
#1. First create a directory say 'db' under the Project folder.
#2. Change the settings.py to include the database section as following:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR,'db/db.sqlite3'),
}
}
#3. Run the python3 manage.py migrate to create the db.sqlite3 file under db directory.
#4. Change the group permissions of the folder db:
 sudo chgrp -R www-data db
#5. Change the access permissions of the folder db:
sudo chown -R 774 db 
6. In the apache site config, include the following to give access to db directory:
 <Directory /Path_To_Project/db>
        Require all granted
    </Directory>

No comments:

Post a Comment