3

I am building backend app using prisma2 + typescript + nexus + graphql-yoga. I have defined my schema now while trying to save migrate by running command:

prisma2 migrate save --name "init" --experimental

Getting the following error.

Error: There are more migrations in the database than locally. This must not happen. Local migration ids: . Remote migration ids: 20200312230215-init, 20200312232858-init2

Penny Liu
  • 15,447
  • 5
  • 79
  • 98
ganesh deshmukh
  • 314
  • 4
  • 17

2 Answers2

9

This is due to a mismatch between the migrations that were executed against the database and the migrations in your prisma/migrations folder.

This happens under the following circumstances:

  1. Create a migration with prisma2 migrate save --name “init” --experimental
  2. Execute the migration with prisma2 migrate up --experimental
  3. Delete the migration files in your prisma/migrations folder
  4. Try to run prisma2 migrate save --name “new-migration” --experimental

At step 4 you will see that error.

Prisma keeps track of the executed migrations in the database in a table called _Migration.

To solve the problem try to delete the _Migration table in the database. With SQLite you can do it as follows:

sqlite3 prisma/dev.db "delete from _Migration"

If that doens't work, you need to recreate the database. If you’re using sqlite, delete the prisma/dev.db file (you will lose all data in the database).

To prevent this in the future, make sure that you start with a clean database and if you reuse the same database avoid deleting migration files (in prisma/migrations after they’ve been executed.

Daniel
  • 1,236
  • 1
  • 9
  • 13
-1

this happens when there are a conflict with the schema.Prisma file and the database which you have used migration you have used the old database and there is a table witch his name _Migration how to solve so please try to drop him by user interface or command line name_database delete from _Migration and try to exec yarn prisma migrate save --experimental or prisma2 migrate save --name “new-migration” --experimental it should be work

Mohammed Al-Reai
  • 2,344
  • 14
  • 18