prisma: `prisma migrate` fails with MySQL

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

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 23 (11 by maintainers)

Commits related to this issue

Most upvoted comments

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

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

@javierfuentesm fyi. I’m using a local instance, so I have full control. I’m also using the latest MariaDB and the latest blitz.js. I recommend joining the slack channel and seeing when the next release incorporates 2.15.

We are working on adding a way to configure a location for the shadow database when you can’t create temporary logical database on your dev database. But for now, there is no workaround except changing your setup (getting permission, switching to a local database you have control over).