If you want to use sqlite as a database for your Django project you need to do three things
- create a volume in your application settings
- ensure your settings file respects
DATABASE_URL
for populating DATABASES object - set the environment variable
DATABASE_URL
that would point to a file within the volume.
Explanation:
The reason why you can't use the path within your codebase folder is because apps are running in containers.
Containers use ephemeral file system, which means data is not persisted between containers and containers restarts.
To prevent that from going unnoticed our built-in Docker images prevent from writing to the code folder.
Create a volume for Sqlite Database file¶
Go to your application settings, switch to Volumes tab.
Click "+Add" button and in the form only specify the "Container path" set it to "/db/"
Now go to the "Environment Variables" tab and add a variable "DATABASE_URL" with the value sqlite:////db/db.sqlite3
(yes, four slashes!)
Hit the "Save and deploy" button, wait for your deployment to finish.
Now your project is using sqlite database.