Deploying Strapi (PG) to DigitalOcean - DB Conflict

System Information
  • Strapi Version: 3.6.11
  • Operating System: MacOS
  • Database: Postgress
  • Node Version: v18.17.0
  • Yarn Version: 1.22.21

Dear Strapi Forum Users,

I have setup a local database (SQLLite) which I previously filled with data for my Strapi CMS. Now I have deployed the backend on DigitalOcean and I have added a database there to my application. I want to connect my database with the digital Ocean DB so it retrieves the data from there.

How ever for some reason my database kept overwriting my live data when published and it for some reason does not work. I have setup the config/env/production/database.js file as following provided by the strapi documentation and a tutorial on YT:

module.exports = ({ env }) => ({
  connection: {
    client: "postgres",
    connection: {
      host: env("DATABASE_HOST", "127.0.0.1"),
      port: env.int("DATABASE_PORT", 5432),
      database: env("DATABASE_NAME", "strapi"),
      user: env("DATABASE_USERNAME", "strapi"),
      password: env("DATABASE_PASSWORD", "strapi"),
      schema: env("DATABASE_SCHEMA", "public"), // Not required
      ssl: {
        ca: env("DATABASE_CA"), // For self-signed certificates
      },
    },
    debug: false,
  },
});

Now my Env variables inside DigitalOcean look as following:

The error I am receiving is the following error:
[2024-01-07 08:54:05] [2024-01-07 08:54:05.783] debug: :no_entry: Server wasn’t able to start properly.
[2024-01-07 08:54:05] [2024-01-07 08:54:05.785] error: create table “public”.“components_contact_information_section_contact_information_sections_components” (“id” serial primary key, “entity_id” integer null, “component_id” integer null, “component_type” varchar(255) null, “field” varchar(255) null, “order” double precision null) - relation “components_contact_information_section_contact_information_sect” already exists
[2024-01-07 08:54:05] error: create table “public”.“components_contact_information_section_contact_information_sections_components” (“id” serial primary key, “entity_id” integer null, “component_id” integer null, “component_type” varchar(255) null, “field” varchar(255) null, “order” double precision null) - relation “components_contact_information_section_contact_information_sect” already exists
[2024-01-07 08:54:05] at Parser.parseErrorMessage (/workspace/backend/node_modules/pg-protocol/dist/parser.js:287:98)
[2024-01-07 08:54:05] at Parser.handlePacket (/workspace/backend/node_modules/pg-protocol/dist/parser.js:126:29)
[2024-01-07 08:54:05] at Parser.parse (/workspace/backend/node_modules/pg-protocol/dist/parser.js:39:38)
[2024-01-07 08:54:05] at TLSSocket. (/workspace/backend/node_modules/pg-protocol/dist/index.js:11:42)
[2024-01-07 08:54:05] at TLSSocket.emit (node:events:517:28)
[2024-01-07 08:54:05] at TLSSocket.emit (node:domain:489:12)
[2024-01-07 08:54:05] at addChunk (node:internal/streams/readable:368:12)
[2024-01-07 08:54:05] at readableAddChunk (node:internal/streams/readable:341:9)
[2024-01-07 08:54:05] at Readable.push (node:internal/streams/readable:278:10)
[2024-01-07 08:54:05] at TLSWrap.onStreamRead (node:internal/stream_base_commons:190:23)
[2024-01-07 08:54:05] error Command failed with exit code 1.
[2024-01-07 08:54:05] info Visit yarn run | Yarn for documentation about this command.

What is the issue that causes this problem? I have been trying for a couple of hours already to fix this issue but for some reason it does not work. I have installed the pg library in my backend.

I’m gonna put a massive asterisk on this response because I am a beginner but from what I understand having just taught myself Strapi → Digital Ocean deployment…

If I were you I would try to export the data on the local database and then ssh it to your Digital Ocean console and import it from there. Data getting overwritten upon deployment is a natural limitation of Strapi. So making use of their data managment features is necessary.

Also, I know that exact YouTube tutorial you mentioned - I recently taught myself how to host my Strapi backend on Digital Ocean as well lol. I believe it is outdated. I followed this documentation to get mine to work: https://docs.strapi.io/dev-docs/deployment/digitalocean-app-platform.