prisma: Changing a column from `Int` to `BigInt` creates an invalid migration `Postgres`

Bug description

When changing a column from Int to BigInt prisma generates an invalid migration.

Example:

ALTER TABLE "my_model" DROP CONSTRAINT "my_model_pkey",
ALTER COLUMN "id" SET DATA TYPE BIGSERIAL,
ADD CONSTRAINT "my_model_pkey" PRIMARY KEY ("id");

Postgres throws the following error:

Database error code: 42704

Database error:
ERROR: type "bigserial" does not exist

DbError { severity: "ERROR", parsed_severity: Some(Error), code: SqlState(E42704), message: "type \"bigserial\" does not exist", detail: None, hint: None, position: None, where_: None, schema: None, table: None, column: None, datatype: None, constraint: None, file: Some("parse_type.c"), line: Some(270), routine: Some("typenameType") }

How to reproduce

  1. Create a schema with a model with id as Int
  2. Migrate and make the DB up to date with the schema
  3. Change the type of the id column from Int to BigInt
  4. Create a migration

Prisma will now generate an invalid migration

Expected behavior

Prisma is able to generate a valid migration

Prisma information

Before

model MyModel {
  id        Int   @id @default(autoincrement())

  @@map("my_model")
}

After:

model MyModel {
  id        BigInt   @id @default(autoincrement())

  @@map("my_model")
}

Environment & setup

  • OS: macOS
  • Database: PostgreSQL
  • Node.js version: 16.19

Prisma Version

prisma                  : 4.11.0
@prisma/client          : 4.11.0

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Reactions: 16
  • Comments: 19 (3 by maintainers)

Most upvoted comments

I can confirm changing primary key type from Int to BigInt causes following error on PostgreSQL:

Database error:
ERROR: type "bigserial" does not exist

It’s sad that Prisma doesn’t support this. It’s super-simple in PostgreSQL.

Once you edit your Prisma schema and generate (but do not apply) migration.sql file, you just need to replace the commands touching the id field with the following:

ALTER SEQUENCE "my_model_id_seq" AS BIGINT;
ALTER TABLE "my_model" ALTER ID TYPE BIGINT;

You don’t need to drop my_model_pkey or do anything like that.

Same here: PosgreSQL: 16 prisma : 4.13.0

Why is this tagged unconfirmed? Reproduction is trivial and examples are provided. This also seems to be a known caveat with Postgres (regardless of version) https://stackoverflow.com/questions/31965506/postgresql-column-type-conversion-from-bigint-to-bigserial. I’m also hitting this.

Issue is still occurring. PostgreSQL 16.3 Prisma 5.15

I think this is a Prisma problem, it is the same as:

https://github.com/go-gorm/postgres/issues/65

it’s unfortunate (and a bit strange on pg’s behalf) that bigserial is not allowed when using ALTER TABLE

If you search around, there are a lot of people who get the error. “ERROR: type “bigserial” does not exist”

PosgreSQL: 14.9

Hi, I found myself running into this. How can this be solved properly? I’m on Neon’s PostgreSQL v15.

Why is this tagged unconfirmed?

Because no one from our team did run any of those reproductions to confirm they indeed let you confirm the bug.

@janpio Im using the postgres:14.1-alpine-docker image, so I guess 14.1!