question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Public UUID postgre migrate error !

See original GitHub issue

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.

Screen Shot 2021-04-08 at 22 09 13

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:

  1. Go to schema.prisma
  2. 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
}
  1. Run npx prisma migrate dev
  2. 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:open
  • Created 2 years ago
  • Reactions:1
  • Comments:29 (16 by maintainers)

github_iconTop GitHub Comments

2reactions
tomhoulecommented, Apr 9, 2021

We have an internal issue about documenting this better.

1reaction
kokokenadacommented, Jun 16, 2022

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 run prisma migrate dev. The only workaround I have found so far is to use a shadow database and manually add the extension there.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error while changing database engine to PostgreSQL
You probably need to delete the initial migration, drop the table, and run migrations with UUID on the id column, as it seems...
Read more >
Postgres migration ERROR: function uuid_generate_v4 ...
Bug description. I created a migration with a schema similar to the one below. Running prisma migrate dev --name init fails with the...
Read more >
Error about UUID UUID_GENERATE_V - DBA Stack Exchange
After migrating to a new db server, I find these errors : [ERR] 9> create or replace function "public".
Read more >
Postgres DB duplicate key Error by updating from Sonarqube ...
Hello, I am trying to update from sonarqube 9.6 to 9.7 via /setup. The Server version is postgres 11.16. The migration process fails...
Read more >
Prisma schema API (Reference)
User: johndoe; Password: mypassword; Host: localhost; Port: 5432; Database name: mydb; Schema name: public. datasource db {. provider = "postgresql".
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found