Skip to content

migrate dev is broken for simple MySQL schema #11204

Open

Description

@janpio

Schema:

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

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

model comments {
  id      Int    @id @default(autoincrement())
  content String
}

Leads to this for me:

C:\Users\Jan\Documents\throwaway\11177>npx prisma migrate dev
Environment variables loaded from .env
Prisma schema loaded from prisma\schema.prisma
Datasource "db": MySQL database "sapphire_parakeet" at "mysql-db-provision.cm0mkpwj8arx.eu-central-1.rds.amazonaws.com:3306"

√ Enter a name for the new migration: ... first
Applying migration `20220114220406_first`

The following migration(s) have been created and applied from new schema changes:

migrations/
  └─ 20220114220406_first/
    └─ migration.sql

Your database is now in sync with your schema.

✔ Generated Prisma Client (3.8.1 | library) to .\node_modules\@prisma\client in 79ms



C:\Users\Jan\Documents\throwaway\11177>npx prisma migrate dev
Environment variables loaded from .env
Prisma schema loaded from prisma\schema.prisma
Datasource "db": MySQL database "sapphire_parakeet" at "mysql-db-provision.cm0mkpwj8arx.eu-central-1.rds.amazonaws.com:3306"

Drift detected: Your database schema is not in sync with your migration history.

The following is a summary of the differences between the expected database schema given your migrations files, and the actual schema of the database.

It should be understood as the set of changes to get from the expected schema to the actual schema.

[*] Changed the `foo` table
  [+] Added column `content`
  [+] Added column `id`

√ We need to reset the MySQL database "sapphire_parakeet" at "mysql-db-provision.cm0mkpwj8arx.eu-central-1.rds.amazonaws.com:3306".
Do you want to continue? All data will be lost. ... yes

Applying migration `20220114220406_first`

The following migration(s) have been applied:

migrations/
  └─ 20220114220406_first/
    └─ migration.sql
√ Enter a name for the new migration: ... second
Applying migration `20220114220430_second`
Error: P3018

A migration failed to apply. New migrations cannot be applied before the error is recovered from. Read more about how to resolve migration issues in a production database: https://pris.ly/d/migrate-resolve

Migration name: 20220114220430_second

Database error code: 1060

Database error:
Duplicate column name 'content'

Please check the query number 1 from the migration file.

Activity

  1. added
    bug/0-unknown
    kind/bug
    topic: prisma migrate dev
    bug/1-unconfirmed
    and removed
    bug/0-unknown
    on Jan 17, 2022
  2. added this to the 3.9.0 milestone on Jan 17, 2022
  3. tomhoule commented on Jan 17, 2022

    @tomhoule
    Contributor

    2022-01-17_13-01-47

    I can't reproduce this behaviour (tried both prisma 3.5 and 3.8, on MySQL 8).

    Do you still have the migration file?

  4. janpio commented on Jan 17, 2022

    @janpio
    ContributorAuthor

    First:

    -- CreateTable
    CREATE TABLE `comments` (
        `id` INTEGER NOT NULL AUTO_INCREMENT,
        `content` VARCHAR(191) NOT NULL,
    
        PRIMARY KEY (`id`)
    ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

    Second:

    /*
      Warnings:
    
      - Added the required column `content` to the `comments` table without a default value. This is not possible if the table is not empty.
    
    */
    -- AlterTable
    ALTER TABLE `comments` ADD COLUMN `content` VARCHAR(191) NOT NULL,
        ADD COLUMN `id` INTEGER NOT NULL AUTO_INCREMENT;
  5. tomhoule commented on Jan 17, 2022

    @tomhoule
    Contributor

    I managed to reproduce this by using the same internal database provisioning tool to create the MySQL database. My takeaway is that it is unclear whether it's a problem with the provisioning tool or migrate.

  6. added
    bug/2-confirmed
    and removed
    bug/1-unconfirmed
    on Jan 19, 2022
  7. added
    tech/engines
    on Mar 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug/2-confirmedkind/bugtech/enginestopic: mysqltopic: prisma migrate dev

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions