Public UUID postgre migrate error !
See original GitHub issueBug description
I created a new project from scratch then I added @id @default(dbgenerated("public.gen_random_uuid()"))
one of id field.The database was created on PostgreSql.
After that, I want to add a new column to our existing schema.prisma .When I run npx prisma migrate dev
It returns this error Migration 20210405204104_202005042340
failed to apply cleanly to a temporary database.
We are using custom uuid which describe like this => @id @default(dbgenerated(“public.gen_random_uuid()”)) @db.Uuid
How to reproduce
Steps to reproduce the behavior:
- Go to schema.prisma
- Add relation
model Author {
id String @id @default(dbgenerated("public.gen_random_uuid()")) @db.Uuid
name String
confirmedBy User? @relation("User", fields: [confirmedById], references: [id])
confirmedById String? @db.Uuid
}
- Run npx prisma migrate dev
- See error
Error: P3006
Migration `20210405204104_202005042340` failed to apply cleanly to a temporary database.
Error:
Database error
Error querying the database: db error: ERROR: function public.gen_random_uuid() does not exist
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
0: sql_migration_connector::flavour::postgres::sql_schema_from_migration_history
at migration-engine/connectors/sql-migration-connector/src/flavour/postgres.rs:278
1: sql_migration_connector::sql_database_migration_inferrer::validate_migrations
at migration-engine/connectors/sql-migration-connector/src/sql_database_migration_inferrer.rs:88
2: migration_core::api::DevDiagnostic
at migration-engine/core/src/api.rs:95
Expected behavior
We were waiting for the database to be updated successfully migrated
Prisma information
model User { id String @id @default(dbgenerated(“public.gen_random_uuid()”)) @db.Uuid email String? Author Author[] @relation(“User”) }
model Author { id String @id @default(dbgenerated(“public.gen_random_uuid()”)) @db.Uuid name String confirmedBy User? @relation(“User”, fields: [confirmedById], references: [id]) confirmedById String? @db.Uuid }
Environment & setup
- OS: Mac OS
- Database: PostgreSQL
- Node.js version: v14.16.0
- Prisma version: 2.20.1
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:29 (16 by maintainers)
Top GitHub Comments
We have an internal issue about documenting this better.
This problem has been a major complication as I attempt to change from Hasura migrations to prisma migrate. The work around of adding
CREATE EXTENSION pgcrypto;
as described by https://www.prisma.io/docs/guides/database/developing-with-prisma-migrate/enable-native-database-functions (even as a separate initial migration) simply does not work when you runprisma migrate dev
. The only workaround I have found so far is to use a shadow database and manually add the extension there.