`prisma migrate` fails with MySQL
See original GitHub issueBug 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
- Create a new project (
yarn add -D @prisma/cli
,yarn prisma init
) - Change
provider
inprisma/schema.prisma
to"mysql"
- Change database details in
prisma/.env
to point to an appropriate MySQL db - Add a simple model the the Prisma schema, something like this just to test
model User {
id Int @default(autoincrement()) @id
}
- Run
yarn prisma migrate save --experimental
- Run
yarn prisma migrate up --experimental
- 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:
- Created 3 years ago
- Comments:23 (11 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I had the same issue (using MariaDB with Docker).
Here’s how i fixed
prisma migrate dev --preview-feature
in case anyone is stuck:Instead of granting
CREATE *.*
only you should also grantDROP *.*
, so the shadow database can be removed after running the migration.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