ERROR: cannot use column reference in DEFAULT expression

See original GitHub issue

Bug description

I am receiving an error when I apply a new migration for the database.

It is weird because is a new database and there are no others migrations before.

How to reproduce

Create a new database using PostgreSQL and apply this Prisma schema using "npx prisma migrate dev".

Expected behavior

No response

Prisma information

schema.prisma

// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

model Hoster {
  id                   String                     @id
  name                 String
  authenticationMethod HosterAuthenticationMethod
  limits               Json
  downloads            Download[]
}

enum HosterAuthenticationMethod {
  FREE
}

model Download {
  id             String         @id @default(dbgenerated("uuid"))
  downloadId     String
  priority       Int            @default(0)
  downloadStatus DownloadStatus
  fingerprint    String
  Hoster         Hoster         @relation(fields: [hosterId], references: [id])
  hosterId       String

  @@unique([downloadId, hosterId])
}

enum DownloadStatus {
  PENDING
  WAITING_DOWNLOAD
  SUCCESS
  FAILED
}

Environment & setup

  • OS: Linux
  • Database: PostgreSQL v14
  • Node.js version: v16.13.2

Prisma Version

node ➜ /workspace (feature/prisma ✗) $ npx prisma -v
prisma                  : 3.9.2
@prisma/client          : Not found
Current platform        : debian-openssl-1.1.x
Query Engine (Node-API) : libquery-engine bcc2ff906db47790ee902e7bbc76d7ffb1893009 (at node_modules/@prisma/engines/libquery_engine-debian-openssl-1.1.x.so.node)
Migration Engine        : migration-engine-cli bcc2ff906db47790ee902e7bbc76d7ffb1893009 (at node_modules/@prisma/engines/migration-engine-debian-openssl-1.1.x)
Introspection Engine    : introspection-core bcc2ff906db47790ee902e7bbc76d7ffb1893009 (at node_modules/@prisma/engines/introspection-engine-debian-openssl-1.1.x)
Format Binary           : prisma-fmt bcc2ff906db47790ee902e7bbc76d7ffb1893009 (at node_modules/@prisma/engines/prisma-fmt-debian-openssl-1.1.x)
Default Engines Hash    : bcc2ff906db47790ee902e7bbc76d7ffb1893009
Studio                  : 0.457.0

Issue Analytics

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

github_iconTop GitHub Comments

3reactions
janpiocommented, Feb 20, 2022

id String @id @default(dbgenerated(“uuid”))

This tries to create a default that refers to the column uuid: "id" TEXT NOT NULL DEFAULT uuid,. You will either have to use a PostgreSQL function in there or replace the dbgenerated with a Prisma level function.

1reaction
felinto-devcommented, Feb 20, 2022

id String @id @default(dbgenerated(“uuid”))

This tries to create a default that refers to the column uuid: "id" TEXT NOT NULL DEFAULT uuid,. You will either have to use a PostgreSQL function in there or replace the dbgenerated with a Prisma level function.

I close the issue because I don’t think is a bug. If you believe it, please, feel free to open it again!

Read more comments on GitHub >

github_iconTop Results From Across the Web

cannot use column reference in DEFAULT expression
cannot use column reference in DEFAULT expression - trying to set up default value for custom column name ; CREATE TABLE IF ;...
Read more >
Error: Cannot use column reference in DEFAULT expression
Add a new column that is of text type (SingleLineText,LongText,SingleSelect,MultiSelect, etc.) Specify the default value that is not a number.
Read more >
Re: cannot use column references in default expression?
expression (subqueries and cross-references to other columns in the > current table are not allowed). The data type of the default
Read more >
[GENERAL] cannot use column references in default ... - narkive
DEFAULT (ID IS NULL) CHECK (isHuman = ID IS NULL), Name VARCHAR NOT NULL); ERROR: cannot use column references in default expression techdb=>...
Read more >
trying to set up default value for custom column name-postgresql
Gives the error: ERROR: cannot use column reference in DEFAULT expression SQL state: 0A000. But if I remove the "" and just put...
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