Public UUID postgre migrate error !
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 47.6k
- Forks
- 2.5k
- Avg merge
- 21h 59m
- Merged PRs (30d)
- 95
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with schema.prisma, the migration history, and the PostgreSQL migration-engine paths named in the error: postgres.rs and sql_database_migration_inferrer.rs. Reproduce with npx prisma migrate dev against PostgreSQL and inspect how the temporary database applies the migration. Done means the migration applies cleanly while retaining the custom UUID defaults and relation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- node.js, postgresql
- Domain
- database
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100