prisma: Public UUID postgre migrate error !
Bug 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
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 4
- Comments: 35 (18 by maintainers)
We have an internal issue about documenting this better.
Open a new issue please and provide all the information it asks for. Thanks.
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.Scheduling this for reproduction.
@erdoganabaci — The migration will be executed after the other migration — the execution order is the alphanumerical order of the migration directories (this is the reason for the timestamps). What happens if you rename the
initial_migrationfolder to0000_initial_migration?@erdoganabaci not sure, but I think the
CREATE EXTENSIONmight need to be in a separate migration file that is executed first, before you can use it.@janpio @pantharshit00 still same error I added top of the place on the migration.sql file but same error even I change the database url I used fresh db and both command
npx prisma migrate dev --create-onlyandnpx prisma migrate devHere there is screenshot
At the top optimally, so it will be available when the
CREATE TABLEis executed.firstly thanks for replying @janpio can you give more details how can i modify migrations.sql file under the prisma folder ? also i run npx prisma migrate dev --create-only this command still same error