Data stored in database deleted each time i deploy a new commit

i use render to deploy my project , first i create a database on render then a web service .
i connect them with the database internal url . it works fine , but i have a big annoying problem : each time i deploy a new commit or the api endpoint is reloaded from the browser , all the data stored in the database is deleted …

here is my code

if DEBUG :
DATABASES = {
“default”: {
“ENGINE”: “django.db.backends.sqlite3”,
“NAME”: BASE_DIR / “db.sqlite3”,
}
}

else :
DATABASES = {
‘default’: dj_database_url.parse(os.getenv(“DATABASE_URL”))

}

i pass the DATABASE_URL in the environment variables on render , plz i need the solution as fast as possible ,it is my graduation project .

Hi,

Render instances have an ephemeral filesystem, meaning any file written to the instance after it has booted will be lost when it next restarts (e.g. spun down if on free instance type, next deploy, manual restart, etc.).

If you’re using SQLite on your service, you’ll need to have a persistent store, a Render Disk (which is chargeable and also requires a paid instance type).

However, your code snippet shows you have a conditional on DEBUG, is that set correctly?

DEBUG = os.getenv(‘DEBUG’) , here is it and i pass False in the enviroment variable on server
, i use database postgres created on render not sqlite as i do in the development phase

So DEBUG is a string of False, not a true boolean?

I’m not a Python expert, but if it’s just a string, I think Python will always evaluate that to true.

Maybe try being more explicit in your DATABASES conditional?

if DEBUG == 'True':

great , it solved thanks

We’re getting deeper into general code debugging here, and not a direct Render issue, which is beyond the scope of our support.

Maybe other community members will be able to assist, or Googling the error (“django InconsistentMigrationHistory”) will likely bring up possible causes/solutions.

1 Like