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
- 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
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 23 (11 by maintainers)
Commits related to this issue
- Update required privileges on MySQL based on user feedback See comment in https://github.com/prisma/prisma/issues/4723 — committed to prisma/docs by albertoperdomo 3 years ago
- Update required privileges on MySQL based on user feedback (#1191) See comment in https://github.com/prisma/prisma/issues/4723 — committed to prisma/docs by albertoperdomo 3 years ago
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
@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).