Problem with model and existing db

Hi,
I have a postgresql db that already have tables populated with tons of data.
I could not use the “prisma pull” cli as prisma does not handle cross schema references (yet, #1175), so I crated the model to one of the tables manually in the schema.prisma file:

model Source {
  id                   Int       @id @default(autoincrement())
  name                 String?
  name_acronym         String?
  description          String?
  url                  String?
  contract             String?
  date_start           DateTime?
  date_end             DateTime?
  original_id          String?
  original_create_date DateTime?
  original_update_date DateTime?
  active               Int?      @default(1)
  create_by            String?
  create_date          DateTime?
  update_by            String?
  update_date          DateTime?
  @@map(name: "sources")

}

I created cell, page, and service using yarn rw scaffold source cli.

When I try to get to: localhost:8910\sources i get the following error:

Invalid prisma.source.findMany()  invocation:

The table `gvg.Source` does not exist in the current database.

The table is accessible using prisma studio.

I tried changing the service from:

export const sources = () => {
  return db.source.findMany()
}

to

export const sources = () => {
  return db.sources.findMany()
}

but then I get the error: Cannot read property 'findMany' of undefined

Any thoughts on how to fix it, as I have about 20 more tables with relationship between then in the db with around 80M records, that I would like to access?

Thank you,
Wiezman

Whoops :sweat_smile: Just saw something I didn’t before which means my input was redundant.

It’s pretty strange how it says :thinking: :

The table `gvg.Source` does not exist in the current database.

when it is accessible via prisma studio.

Did you try introspecting you database instead?

You will want to be careful if you point to production data when you migrate and use deploy Deploying database changes with Prisma Migrate | Prisma Docs such that you aren’t resetting or recreating tables in prod.

I’d recommend you develop of a local db with the schema or a snapshot of production until you get your app’s schema in sync.

You’ll also need to be sure the prisma client is generated.

I didn’t try that on the prod db. I have a copy that I use for dev. Thank you for the warning though.

@dthyresson, I cannot use introspecting as Prisma introspect does not support cross schema connection, references, and keys.
I had to manually create the model in schema.prisma

If I change the table name in the db to Source, the issue goes away. Unfortunately, I cannot change the table name permanently, as it is used in the production application.

Any other thoughts?

This is known issue with how redwood handles model names internally. When you pass model name to generate command it is translated to PascalCase automatically by redwood js, which obviosly does not exist in database.
For more details: Support snake_case in `generate` command · Issue #2401 · redwoodjs/redwood · GitHub