P
Prisma2w ago
Domica

Prisma migrate dev keeps wanting to drop my sequence

I created an empty migration file, added my sequence in. After that I ran migrate dev which will generate the sql necessary to insert my column orderNumber Int? @unique @default(dbgenerated("nextval('order_number_seq')")) It creates the sql for inserting that column
-- AlterTable
ALTER TABLE "Order" ADD COLUMN "orderNumber" INTEGER DEFAULT nextval('order_number_seq');

-- CreateIndex
CREATE UNIQUE INDEX "Order_orderNumber_key" ON "Order"("orderNumber");
-- AlterTable
ALTER TABLE "Order" ADD COLUMN "orderNumber" INTEGER DEFAULT nextval('order_number_seq');

-- CreateIndex
CREATE UNIQUE INDEX "Order_orderNumber_key" ON "Order"("orderNumber");
But after running migrate dev again, it keeps creating a new migration with this content
-- AlterTable
ALTER TABLE "Order" ALTER COLUMN "orderNumber" SET DEFAULT nextval('order_number_seq'),
ALTER COLUMN "orderNumber" DROP DEFAULT;
DROP SEQUENCE "order_number_seq";
-- AlterTable
ALTER TABLE "Order" ALTER COLUMN "orderNumber" SET DEFAULT nextval('order_number_seq'),
ALTER COLUMN "orderNumber" DROP DEFAULT;
DROP SEQUENCE "order_number_seq";
add_sequence.sql migration -
CREATE SEQUENCE order_number_seq START 1000000;
CREATE SEQUENCE order_number_seq START 1000000;
I'm unsure why this is happening
1 Reply
RaphaelEtim
RaphaelEtim2w ago
Hi @Domica Can you try doing prisma db pull when you work with dbgenerated? This is mentioned in the documentation. You can also take a look at this related issue.
GitHub
Prisma migrate incorrectly infers new migration needed when `dbgene...
Bug description Giving a default db generated value with a string in it leads Prisma Migrate to think a new migration is always needed: datasource db { provider = "cockroachdb" // ... } m...
Prisma Schema API | Prisma Documentation
API reference documentation for the Prisma Schema Language (PSL).
Want results from more Discord servers?
Add your server