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.

Unwanted migration generate every time running `prisma migrate dev` with edited migration file that enables Postgres extensions

See original GitHub issue

Bug description

In my project, I need to use UUID on the db side and so I followed this guide and edited the file as

CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; -- Added this only
-- CreateTable
CREATE TABLE "accounts" (
    "id" UUID NOT NULL DEFAULT public.uuid_generate_v4(),

    CONSTRAINT "accounts_pkey" PRIMARY KEY ("id")
);

Then every time when I run prisma migrate dev, it prompts me to create a new migration. But the migration is doing nothing:

-- AlterTable
ALTER TABLE "accounts" ALTER COLUMN "id" SET DEFAULT public.uuid_generate_v4();

How to reproduce

  1. run prisma migrate dev --create-only
  2. add CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; to the first line of the generated file
  3. prisma migrate status correctly gives Database schema is up to date!
  4. run prisma migrate dev, then it prompts ✔ Enter a name for the new migration:

Expected behavior

Should correctly detects the schema is up to date and no new migration is needed

Prisma information

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

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

model Account {
  id String @id @default(dbgenerated("public.uuid_generate_v4()")) @db.Uuid()

  @@map("accounts")
}

Environment & setup

  • OS: macOS 12.1
  • Database: Postgres
  • Node.js version: v16.13.0

Prisma Version

prisma                  : 3.10.0
@prisma/client          : 3.10.0
Current platform        : darwin
Query Engine (Node-API) : libquery-engine 73e60b76d394f8d37d8ebd1f8918c79029f0db86 (at node_modules/@prisma/engines/libquery_engine-darwin.dylib.node)
Migration Engine        : migration-engine-cli 73e60b76d394f8d37d8ebd1f8918c79029f0db86 (at node_modules/@prisma/engines/migration-engine-darwin)
Introspection Engine    : introspection-core 73e60b76d394f8d37d8ebd1f8918c79029f0db86 (at node_modules/@prisma/engines/introspection-engine-darwin)
Format Binary           : prisma-fmt 73e60b76d394f8d37d8ebd1f8918c79029f0db86 (at node_modules/@prisma/engines/prisma-fmt-darwin)
Default Engines Hash    : 73e60b76d394f8d37d8ebd1f8918c79029f0db86
Studio                  : 0.458.0

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:3
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
Repomncommented, Nov 11, 2022

Any updates? It happens on me after updating version to 4.6.0 from 3.0.1.

schema

model Hoge {
  id                  String      @id @default(uuid())
  type                HogeType    @default(A)
  // ...
}

enum HogeType {
  A
  B
  C
  // ...
}

migration

-- AlterTable
ALTER TABLE "Hoge" DROP COLUMN "type",
ADD COLUMN     "type" "HogeType" NOT NULL DEFAULT 'A';
1reaction
RickEyrecommented, May 23, 2022

Happening for me as well.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Prisma Migrate | Database, Schema, SQL Migration Tool
Prisma Migrate is a database migration tool available via the Prisma CLI that integrates with Prisma schema for data modeling.
Read more >
Migration troubleshooting in development - Prisma
This guide describes how to resolve issues with Prisma Migrate in a development environment, which often involves resetting your database.
Read more >
Squashing migrations - Prisma
This guide describes how to squash multiple migration files into a single migration. About squashing migrations. It is sometimes useful to squash either ......
Read more >
Adding Prisma Migrate to an existing project
Check out a copy of the repository with the new migration directory and the schema.prisma file · Run the following command to reset...
Read more >
Customize a migration file - Prisma
Make a schema change that requires custom SQL (for example, to preserve existing data) · Create a draft migration using: $npx prisma migrate...
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