简体   繁体   中英

How to fix Error: MD5 checksum failed for migration [1] npm ERR! code ELIFECYCLE npm ERR! errno 1

I keep running into this error

noteful-json-server@0.0.1 migrate /Users/jessicayiphome/Desktop/Projects/noteful-client-db-master-17.19
> postgrator --config postgrator-config.js

[11:04:50 AM] version of database is: 2
[11:04:50 AM] migrating up to 2
[11:04:50 AM] verifying checksum of migration 001.do.create_folders_table.sql
Error: MD5 checksum failed for migration [1]
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! noteful-json-server@0.0.1 migrate: `postgrator --config postgrator-config.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the noteful-json-server@0.0.1 migrate script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/jessicayiphome/.npm/_logs/2020-08-25T15_04_50_228Z-debug.log

when I run npm run migrate Here is my package.json:

"scripts": {
"test": "mocha --require test/setup.js",
"dev": "nodemon src/server.js",
"migrate": "postgrator --config postgrator-config.js",
"migrate:test": "env NODE_ENV=test npm run migrate",
"migrate:production": "heroku run npm run migrate",
"start": "node src/server.js",
"deploy": "git push heroku master",
"postdeploy": "npm run migrate:production"

and here is my postgrator-config.js

'use strict';
require('dotenv').config();

module.exports = {
  "migrationDirectory": "migrations",
  "driver": "pg",
  "connectionString": process.env.DATABASE_URL
};

What

The error is telling you that the migration script 001.do.create_folders_table.sql has changed since it was first created. To fix the error you need to ensure that the contents of the file are exactly the same as when they were when the script first ran. Can you use git to check out an old version of the file?

Why

The checksum is a string of characters called a hash . It is created by using the script as input to an algorithm called md5. Depending on your machine, you might have a command line version of md5 can try for yourself. Try md5 001.do.create_folders_table.sql and you will see the output. Probably something like: ce662acdd491b642c6db551983f878cd .

Postgrator stores these md5 hashes. To ensure that the database is put into the same state every time the migrations are run, it will put the script through md5 and compare the result with the stored version. If the current version and the sotred version are different, then the script must have changed which means it is not safe to run the migration.

我收到了同样的错误,对我有用的是运行 npm migrate -- 0。然后运行 ​​npm migrate 将它设置为升级的迁移。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM