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.

`prisma migrate` fails with MySQL

See original GitHub issue

Bug description

When trying to create & run a migration using prisma migrate with MySQL, it fails with Error: P1014 The underlying table for model `_migration` does not exist.

This doesn’t happen when using the exact same schema with PostgreSQL - it seems that for MySQL it’s not creating the migrations table, and it also adds a DROP TABLE _migration` into the migration’s README which doesn’t appear under PostgreSQL.

How to reproduce

  1. Create a new project (yarn add -D @prisma/cli, yarn prisma init)
  2. Change provider in prisma/schema.prisma to "mysql"
  3. Change database details in prisma/.env to point to an appropriate MySQL db
  4. Add a simple model the the Prisma schema, something like this just to test
model User {
  id Int @default(autoincrement()) @id
}
  1. Run yarn prisma migrate save --experimental
  2. Run yarn prisma migrate up --experimental
  3. Migration fails with an error code of P1014

Expected behavior

Migration is generated properly and runs as expected without failing.

Prisma information

Base Prisma schema

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

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

model User {
  id Int @default(autoincrement()) @id
}

Environment & setup

  • OS: Windows 10 20H2
  • Database: MariaDB 10.5.8
  • Node.js version: 15.3.0
  • Prisma version:
@prisma/cli          : 2.12.1
@prisma/client       : 2.12.1
Current platform     : windows
Query Engine         : query-engine cf0680a1bfe8d5e743dc659cc7f08009f9587d58 (at node_modules\@prisma\engines\query-engine-windows.exe)
Migration Engine     : migration-engine-cli cf0680a1bfe8d5e743dc659cc7f08009f9587d58 (at node_modules\@prisma\engines\migration-engine-windows.exe)
Introspection Engine : introspection-core cf0680a1bfe8d5e743dc659cc7f08009f9587d58 (at node_modules\@prisma\engines\introspection-engine-windows.exe)
Format Binary        : prisma-fmt cf0680a1bfe8d5e743dc659cc7f08009f9587d58 (at node_modules\@prisma\engines\prisma-fmt-windows.exe)
Studio               : 0.322.0

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:23 (11 by maintainers)

github_iconTop GitHub Comments

2reactions
steschwacommented, Jan 19, 2021

I had the same issue (using MariaDB with Docker).

Error: A migration failed when applied to the shadow database:
P1010

Here’s how i fixed prisma migrate dev --preview-feature in case anyone is stuck:

Instead of granting CREATE *.* only you should also grant DROP *.*, so the shadow database can be removed after running the migration.

GRANT CREATE, DROP ON *.* TO '{YOUR_DB_USERNAME}'@'{YOUR_DB_PRIVILEGES_HOST}';
FLUSH PRIVILEGES;

I think this should be added to the docs too: https://www.prisma.io/docs/concepts/components/prisma-migrate#shadow-database-user-permissions

1reaction
albertoperdomocommented, Jan 22, 2021

The issue about being able to configure the shadow DB URL when you are using migrate dev with cloud-hosted databases can be tracked here: https://github.com/prisma/prisma/issues/4751

When this is live, you should be able to create two databases, one fore development, another for the shadow database, and point Prisma to both. cc @javierfuentesm

Read more comments on GitHub >

github_iconTop Results From Across the Web

Prisma Migrate limitations and known issues
Prisma Migrate generates SQL files that are specific to your provider. This means that you cannot use the same migration files for PostgreSQL...
Read more >
Prisma migration to MySQL on localhost Fails - Stack Overflow
I am new to Prisma & MySQL. I am trying to migrate some sample tables to MySQL. Please, I need your help.
Read more >
Prisma on Twitter: " What do you do when your schema ...
What do you do when your schema migration fails? You now have a tool to compare the state of your migration history or...
Read more >
Effortless database schema migration with Prisma
After Prisma applies the migration files, they should never be manually edited or deleted. Doing this can lead to inconsistencies, forcing ...
Read more >
[Solved]-Prisma ECONNREFUSED error after running prisma ...
[Solved]-Prisma ECONNREFUSED error after running prisma migrate / generate-mysql ... In my case, my issue resolved after install latest Prisma manually. For ...
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