Question

continuous deployment django database

Posted October 5, 2021 77 views
PostgreSQLDjangoDeploymentDigitalOcean Managed PostgreSQL Database

Using the App platform for a Wagtail(django) project, I struggle to continuously deploy my database.

My project’s code is updated upon deployment. I can then enter the data from my server.
Yet, the DB component isn’t updated.

My emote DB can run the project with either sqlite3 or postgres.
While sqlite is simpler for local considerations, I switched to postgres for a continuous deployment.

I added a Db postgres component. But it doesn’t display the deployment modifications. Idem, after I run ‘python manage.py migrate’ command in my server console.

I found plenty of information but no script that is guaranteed to work and is up-to-date.

I’d highly appreciated if you can you advise on the best practice, a barebones example that I can follow step-by-step that would set me on my way.

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.

×
Submit an Answer
1 answer

Hey there!

It sounds like you may be storing your database content within the application and it is getting overwritten on each deploy. Adding a Postgres database as a component would allow it to be accessed by your application using the env variable DATABASE_URL. You would need to configure your application to use that variable to connect to the external database rather then sqlite running within the app. I would recommend you take a look at our Django tutorial on how to configure that connection within your app.

Hope it helps!
Nate

by Mason Egger
Django is a powerful web framework that allows you to deploy your Python applications or websites. Django includes many features such as authentication, a custom database ORM, and an extensible plugin architecture. Django simplifies the complexities of web development, allowing you to focus on writing code. In this tutorial, you'll configure a Django project and deploy it to DigitalOcean's App Platform.
  • Thanks for your return!
    I actually followed this tutorial before.
    On my remote db I enter all variables as specified, on the app-level. But I received an error message:
    raise Exception(“DATABASEURL environment variable not defined”)
    Exception: DATABASE
    URL environment variable not defined

    Also I note that the secret key is set as a env. variable on the remote but it is hard-coded on DO… which is a bit confusing.
    If so, should I copy the secret_key string with our without double quote?