How to handle relations when deploying and connecting to existing psql DB

prisma

#1

My existing database structure looks something like this:

admin_users
  id SERIAL PRIMARY KEY

customers
  admin_user_id INTEGER NOT NULL REFERENCES admin_users(id)
  id SERIAL PRIMARY KEY

I ran prisma introspect and got this schema:

type AdminUser @pgTable(name: "admin_users") {
  id: Int! @unique
}

type Customer @pgTable(name: "customers") {
  adminUser: AdminUser!
  id: Int! @unique
}

After changing the ids to ID I ran prisma deploy and received the following error:

    ✖ Could not find the relation table _AdminUserToCustomer

I then came across the pgRelation directive in the docs, and adjusted the datamodel like so:

type AdminUser @pgTable(name: "admin_users") {
  id: ID! @unique
}

type Customer @pgTable(name: "customers") {
  adminUser: AdminUser! @pgRelation(column: "admin_user_id")
  id: ID! @unique
}

I thought this would do it, but now I’m seeing the following error:

    ✖ Could not find the model table customers in the database

That table absolutely does exist in my local DB.

Just for reference my docker-compose.yml looks like this:

version: '3'
services:
  prisma:
    image: prismagraphql/prisma:1.28
    restart: always
    ports:
      - '4467:4467'
    environment:
      PRISMA_CONFIG: |
        port: 4467
        databases:
          default:
            connector: postgres
            host: host.docker.internal
            database: ...
            user: ...
            password: ...
            rawAccess: true
            port: '5432'
            migrations: false

Any idea what could be the problem here? Thanks :pray:


#2

Hi @jwld

Can you try the latest alpha version of the prisma cli? It has a ton of introspection improvement so this might be already resolved.

Also, if the problem persists, please open a github issue for this.

Thanks,
Harshit


#3

Thanks, no different. Will open an issue!

Done: https://github.com/prisma/prisma/issues/4195


#4

@pantharshit00

I haven’t made any progress on this yet and am quite keen to get it sorted so that I can introduce prisma to a new project in the next couple of weeks.

Do you see anything wrong with the use of @pgRelation above, or do you suspect this is a bug?


#5

Solved :tada:

Just had to add schema: public to my docker-compose.yml. I then also had to change my id fields back to Int (as was originally generated) before it actually worked.