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.

Supabase: function gen_random_uuid() does not exist

See original GitHub issue

Bug description

I am trying to do npx prisma db push to my connection with supabase but I get the following error

Error: Database error Error querying the database: db error: ERROR: function gen_random_uuid() does not exist HINT: No function matches the given name and argument types. You might need to add explicit type cas ts. 0: sql_migration_connector::sql_database_step_applier::apply_migration at migration-engine/connectors/sql-migration-connector/src/sql_database_step_applier.rs :15

I want to generate unique uuids with gen_random_uuid(), According to me, supabase by default has PGCRYPTO installed.

supe

then I would expect the following model to be correct

model Team {
  id          String   @id @default("gen_random_uuid()") @db.Uuid
  name        String
  slug        String   @unique
  description String?
  avatar      String?
  isDefault   Boolean  @default(false)
  createdAt   DateTime @default(now())
  updatedAt   DateTime @updatedAt
  creatorId   String?  @db.Uuid
  members     User[]   @relation(references: [id])
  apps        App[]
}

How to reproduce

Expected behavior

No response

Prisma information

model Team {
  id          String   @id @default("gen_random_uuid()") @db.Uuid
  name        String
  slug        String   @unique
  description String?
  avatar      String?
  isDefault   Boolean  @default(false)
  createdAt   DateTime @default(now())
  updatedAt   DateTime @updatedAt
  creatorId   String?  @db.Uuid
  members     User[]   @relation(references: [id])
  apps        App[]
}

Environment & setup

  • OS: Mac OS,
  • Database: PostgreSQL
  • Node.js version: v16.0.0

Prisma Version

prisma               : 2.24.1
@prisma/client       : 2.24.1
Current platform     : darwin
Query Engine         : query-engine 18095475d5ee64536e2f93995e48ad800737a9e4 (at node_modules/@prisma/engines/query-engine-darwin)
Migration Engine     : migration-engine-cli 18095475d5ee64536e2f93995e48ad800737a9e4 (at node_modules/@prisma/engines/migration-engine-darwin)
Introspection Engine : introspection-core 18095475d5ee64536e2f93995e48ad800737a9e4 (at node_modules/@prisma/engines/introspection-engine-darwin)
Format Binary        : prisma-fmt 18095475d5ee64536e2f93995e48ad800737a9e4 (at node_modules/@prisma/engines/prisma-fmt-darwin)
Default Engines Hash : 18095475d5ee64536e2f93995e48ad800737a9e4
Studio               : 0.397.0

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

6reactions
iwatakeshicommented, Jun 7, 2021

Try @default(dbgenerated("extensions.[name of function here]()")) @db.Uuid. The uuid function(s) is/are located under the extensions schema and this is the result I got when I introspected the database. I’m not sure if the dbgenerated() is needed though.

5reactions
tomhoulecommented, Jun 8, 2021

Hi @iwatakeshi — I haven’t tried it myself but your answer looks right. The “dbgenerated(…)” is necessary because this is a “raw” database-level default that migrate and introspection understand, but prisma client doesn’t, it just knows there’s a default.

Read more comments on GitHub >

github_iconTop Results From Across the Web

"Error function gen_random_uuid() does not exist" #2764
Getting "Error function gen_random_uuid() does not exist" when an event trigger on a table of another shema than the "public" is trigger.
Read more >
uuid-ossp: Unique Identifiers
Creates UUID values based solely on random numbers. You can also use Postgres's built-in gen_random_uuid() function to generate a UUIDv4. Examples#. Within a ......
Read more >
PostgreSQL function gen_random_uuid() not working
I can see pgcrypto module listed in this query select * from pg_available_extensions; . I'm using PostgreSQL 9.4.5 on Ubuntu 14.04. Did I...
Read more >
JLCA
You had the following error "function gen_random_uuid() does not exist". Trying to Represent default values ​​that cannot be expressed in.
Read more >
Documentation: 15: 9.14. UUID Functions
PostgreSQL includes one function to generate a UUID: gen_random_uuid () → uuid. This function returns a version 4 (random) UUID. This is the...
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