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.

Migration continually recreated despite schema not changing - dbgenerated nextval

See original GitHub issue

Bug description

Schema is not changed but migration is continually recreated for a dbgenerated id:

id String @id @default(dbgenerated("'policy_'|| nextval('policy_seq')"))

I have tried various syntaxes to no avail. Postgres shows it as: id text COLLATE pg_catalog."default" NOT NULL DEFAULT ('policy_'::text || nextval('policy_seq'::regclass)),

How to reproduce

Add to schema with Postgres provider:  id String @id @default(dbgenerated("'policy_'|| nextval('policy_seq')"))

Expected behavior

Create an original migration but should not create any more subsequent migrations after the original one. Unfortunately it continually creates a new migration on prisma migrate dev

Prisma information

model Policy {
  id                     String                   @id @default(dbgenerated("'policy_'|| nextval('policy_seq')"))
  name               String                   @unique

  @@map("policy")
}

Environment & setup

  • OS: MacOS
  • Database: PostgreSQL
  • Node.js version: 18

Prisma Version

4.2.0

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
haneymancommented, Aug 15, 2022

That did actually fix the issue, thanks!

0reactions
janpiocommented, Aug 15, 2022

Thanks. That is fortunately pretty close to what Postgres shows itself 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

Prisma v4 breaks support for empty `dbgenerated()` - invalid ...
Worked just fine through prisma 3.15.2; prisma 4.0.0 onwards produces invalid migration with no schema change
Read more >
Why is rails 5 adding nextval method in schema file?
This is a bit long of an answer, so I've broken it into sections. Buckle up! My theory. My guess is that your...
Read more >
Sequences - Oracle to Aurora PostgreSQL Migration Playbook
CYCLE | NOCYCLE : Instructs a sequence to continue generating values despite reaching the maximum value or the minimum value. If the sequence...
Read more >
#24533 (Changing an AutoField into an IntegerField leaks the ...
Change the primary key from an AutoField to an IntegerField: ... and recreate migrations, the sequence is dropped and recreated, avoiding a crash:...
Read more >
Blog | ent
Lint migration files​. Changes to your project's Ent schema almost always result in a modification of your database. If you are using Versioned...
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