18

I am trying to create an API using Strapi CMS. I have an existing PostgreSQL + postgis database and I would like to connect-use this database in a Strapi project.

Do you know if it is possible to do something like this?

7
  • 1
    I never touched Strapi but If I am not wrong, you can modify the connection string in the Strapi project to match with the existing Postgres DB Commented Jun 30, 2020 at 11:33
  • Thanks for the advice, i just tried to connect strapi with the connection string, there is no errors but strapi cannot "see" the existing tables in the database. Any ideas? Thanks Commented Jul 1, 2020 at 8:16
  • could it be that you're connected to wrong database inside of your postgres instance? Commented Jul 1, 2020 at 9:10
  • Unfortunately no, i have also made some changes to the database.json file in order to define the schema (which is used in postgres db). Here is the database file: { "defaultConnection": "default", "connections": { "default": { "connector": "strapi-hook-bookshelf", "settings": { "client": "postgres", "host": "127.0.0.1", "port": 5432, "database": "Testdb", "schema":"public", "username": "postgres", "password": "$$$$$$" }, "options": {} } } } Any other ideas? Thanks Commented Jul 2, 2020 at 7:40
  • 2
    I've got a similar challenge. This slightly different question seemed to help me stackoverflow.com/questions/51171858/… Commented Jul 3, 2020 at 10:41

4 Answers 4

10

It seems the only answer is no, because Strapi is not schema-agnostic: you must adopt their database structure to use Strapi.

Sign up to request clarification or add additional context in comments.

6 Comments

Did you find schema-agnostic headless cms?
Nope. Wound up making my own ... which feels like a huge step backward ("reinventing the wheel") ... but I never found a good alternative.
you can check out directus cms it's schema agnostic and doesn't delete all your tables like strapi did me.. yikes
Directus is only somewhat schema-agnostic. It won't delete tables and you can configure it to use existing ones (a painful process), but good luck trying to get it to use your own intersection tables for many to many relationships, it inevitably tries to create its own when you set up relationship fields. Directus is also a pain to try to configure without UI clicks or across environments, so.. in a similar predicament on various projects as @machineghost
|
5

You can do it while you create a strapi app just choose custom and setup the database there. and to import existing tables from that db just create a mock table using strapi admin panel and in /api folder in your project root folder and copy paste the table data you just created in api folder and chage the name of that folder to the table name and do same for the files in side that folder and,

in the api>(your table folder)>config>routes.json file change the name of table inside I will add a link to help you better understand.

for setup in strapi with existing database> configure-strapi-postgresql

I couldn't find the tut for setting up exist but this is for mysql setps are smilers.

strapi with sql

1 Comment

please be aware of this warning on the strapi page: Strapi applications are not meant to be connected to a pre-existing database, not created by a Strapi application, nor connected to a Strapi v3 database. The Strapi team will not support such attempts. Attempting to connect to an unsupported database may, and most likely will, result in lost data. docs.strapi.io/developer-docs/latest/setup-deployment-guides/…
4

The best way is to create a new database with the same structure but created with strapi and after migrate the data.

Comments

-1

You are creating an API using Strapi CMS. There is no reason why your database should be Strapi database.

Just build your API with Strapi.

Or you can use this tutorial to integrate Strapi into your existing database as @Augusto Rodriguez said.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.