I am trying to add the Prisma DB client to the existing node.js project while preserving the DB structure.
Postgresql Prisma 4.7.1
- I've set up the initial Prisma configuration (env vars, etc.).
- I've used the command
npx prisma db pull
to generateprisma.schema
file according to the existing DB structure - I create the initial migration by using some empty DB
npx prisma migrate dev
At this point it is expected that migration would create DB structure, but the command fails with the following error
✗ npx prisma migrate dev
Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma
Datasource "db": PostgreSQL database "service_prisma", schema "public" at "127.0.0.1:5432"
PostgreSQL database service_prisma created at 127.0.0.1:5432
✔ Enter a name for the new migration: … init
Applying migration `20221221095823_init`
Error: P3018
A migration failed to apply. New migrations cannot be applied before the error is recovered from. Read more about how to resolve migration issues in a production database: https://pris.ly/d/migrate-resolve
Migration name: 20221221095823_init
Database error code: 42883
Database error:
ERROR: function uuid_generate_v4() does not exist
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
DbError { severity: "ERROR", parsed_severity: Some(Error), code: SqlState(E42883), message: "function uuid_generate_v4() does not exist", detail: None, hint: Some("No function matches the given name and argument types. You might need to add explicit type casts."), position: None, where_: None, schema: None, table: None, column: None, datatype: None, constraint: None, file: Some("parse_func.c"), line: Some(521), routine: Some("ParseFuncOrColumn") }
Follow up plan would be to:
- Set DB back to the original one containing tables and data
- Then mark initial migration as applied with the following command
npx prisma migrate resolve --applied 20221221095823_init
So, main problem is that IDs in existing tables use uuid_generate_v4() to generate random UUID for new entries. The support on DB level is definitly there, because it simple works normally with slonik DB client.
model SomeTable {
id String @id @default(dbgenerated("uuid_generate_v4()")) @db.Uuid
}
Any idea how to solve this? Thanks in advance!