In my application i want to create a default primary key where the key must start with BL-
and another rest 9 digits character must be random.
Schema
model myModel {
// try 1
id String @id @default(dbgenerated("BL-"))
// try 2
id String @id @default(dbgenerated("BL-" + substring(uuid(), 1, 8)))
has context menu
Compose
// other fields
}
Migrations
-- AlterTable
ALTER TABLE "businessLoanOffers" ALTER COLUMN "id" SET DEFAULT BLO;
ERROR
Database error code: 0A000
Database error:
ERROR: cannot use column reference in DEFAULT expression
DbError { severity: "ERROR", parsed_severity: Some(Error), code: SqlState(E0A000), message: "cannot use column reference in DEFAULT expression", detail: None, hint: None, position: None, where_: None, schema: None, table: None, column: None, datatype: None, constraint: None, file: Some("parse_expr.c"), line: Some(530), routine: Some("transformColumnRef") }
My other Possible way of solving it would be using JS
to create the primary-key
of my choice but i wanted to solve this issue using prisma
and postresql
.