Report this

What is the reason for this report?

Database are deleting after every deployment to DigitalOcean App Platform - Django

Posted on August 3, 2022

I did my first deployment to DigitalOcean using App Platform, but I have a problem with Database of Django project

Every time i implement some new code or some changes. PostgreSQL database removes all registered data, admin users, posts, … Why is this problem happening? I appreciate any information. I did the deployment according to:

https://docs.digitalocean.com/products/app-platform/

I appreciate your help, thanks

My DB settings:

if not DEBUG:
    # Postgresql config
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.postgresql_psycopg2',
            'NAME': os.environ.get('DB_NAME'),
            'USER': os.environ.get('DB_USER'),
            'PASSWORD': os.environ.get('DB_USER_PASSWORD'),
            'HOST': os.environ.get('DB_HOST'),
            'PORT': os.environ.get('DB_PORT'),
            'SSLMODE': os.environ.get('DB_SSLMODE'),
        }
    }


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hi there,

The App platform uses ephemeral storage, meaning that after each deployment all the files that were stored on the App platform itself would be lost.

You should use a Managed Database with your app rather than running your database inside the App Platform itself:

https://docs.digitalocean.com/products/app-platform/how-to/manage-databases/

And for static files like images, you could use Spaces for persistent storage:

https://docs.digitalocean.com/products/spaces/quickstart/

For more information on how to store data in the App Platform, I would recommend the official docs here:

https://docs.digitalocean.com/products/app-platform/how-to/store-data/

Hope that this helps!

Best,

Bobby

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Start building today

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.