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.

Default function not working

See original GitHub issue

I’ve set the default value for a MySQL column to left(uuid(),8).

After using prisma introspect && prisma generate I get the following schema:

model game {
  id         String    @id @default("left(uuid(),8)")
}

Now, when using game.create prisma writes left(uuid(),8) into the id column.

I’ve tried setting id to null or undefined explicitly, but neither worked.

Is there any workaround for this?

Thanks.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
tomhoulecommented, Mar 3, 2021

Hi @baba43 — the syntax you used is for defining string defaults. If you want an expression as a default, you can use @default(dbgenerated("left(uuid(),8)"). I’d be curious to know if that works for you!

0reactions
pantharshit00commented, Mar 10, 2021

@baba43 If you can also share the SQL of this table, that would help in getting a more accurate reproduction.

Read more comments on GitHub >

github_iconTop Results From Across the Web

The default function argument does not work - Stack Overflow
If you pass undefined as an argument, the "default value" (if present) is assigned ... function range(start = undefined, stop = undefined, ...
Read more >
Defaults function in Power Apps - Microsoft Learn
When you work with a collection or another data source that doesn't support default values, the Defaults function will return an empty record....
Read more >
Default parameters - JavaScript - MDN Web Docs
Default function parameters allow named parameters to be initialized with default values if no value or undefined is passed.
Read more >
Field default do not work | Odoo
I've been working on a module for interests. What I have to do is to make possible to create an invoice which has...
Read more >
Default arguments in member functions do not work in the C++ ...
I tried and default arguments seem to work for non-member functions though. ... This issue is read only, because it has been in...
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