25

When using the sequalize db:migrate command I am getting the following error. Looking at some of the previous comments on similar issues people said it is a dependency issue but whenever I run

npm install mysql2

or

npm install -g mysql2

I get the same error.

larry@DESKTOP-NSSNPRR:/mnt/c/Users/larry/Desktop/node/AAF-NodeJS$
sequelize db:migrate

Sequelize CLI [Node: 10.1.0, CLI: 4.0.0, ORM: 4.37.10]

(node:2241) ExperimentalWarning: The fs.promises API is experimental
Loaded configuration file "db/config/database.json".
Using environment "development".

ERROR: Please install mysql2 package manually

Here is my package.json like some of you have asked for.

{
  "name": "aaf-website-node",
  "version": "0.0.1",
  "description": "Nodejs implementation of the achieve anything website",
  "main": "app.js",
  "scripts": {
    "start": "node bin/www",
    "dev": "node node_modules/nodemon/bin/nodemon.js bin/www",
    "test": "jasmine",
    "console": "node console.js"
  },
  "repository": {
    "type": "git",
    "url": "https://github.com/AchieveGirl/AAF-NodeJS.git"
  },
  "keywords": [
    "nodejs",
    "express"
  ],
  "author": "Larry Cherry",
  "license": "MIT",
  "bugs": {
    "url": "https://github.com/AchieveGirl/AAF-NodeJS/issues"
  },
  "homepage": "https://github.com/AchieveGirl/AAF-NodeJS/blob/master/README.md",
  "dependencies": {
    "body-parser": "^1.18.2",
    "bootstrap": "^4.0.0",
    "compression": "^1.7.2",
    "cookie-parser": "^1.4.3",
    "dotenv": "^5.0.1",
    "ejs": "^2.5.7",
    "eslint": "^4.19.1",
    "express": "^4.16.3",
    "express-ejs-layouts": "^2.3.1",
    "express-minify": "^1.0.0",
    "express-minify-html": "^0.12.0",
    "jquery": "^3.3.1",
    "lodash": "^4.17.5",
    "morgan": "^1.9.0",
    "mysql2": "^1.5.3",
    "node-fetch": "^2.1.2",
    "node-minify": "^2.4.1",
    "popper.js": "^1.14.3",
    "sequelize": "^4.37.10",
    "sequelize-cli": "^4.0.0",
    "serve-favicon": "^2.4.5",
    "webpack": "^4.1.1",
    "webpack-cli": "^2.0.12"
  },
  "devDependencies": {
    "nodemon": "^1.17.2",
    "pryjs": "^1.0.3"
  }
}
Larry Cherry
  • 451
  • 1
  • 4
  • 11

15 Answers15

29

This one worked for me

npm install mysql2 --save

bereket gebredingle
  • 12,064
  • 3
  • 36
  • 47
19

So I finally figured out the bug. The issue appears to come from when you are calling the migration from global install of sequelize-cli instead of the locally installed version of sequelize in my project. All I had to do was call the script form the node modules folder and it worked perfectly. I was calling the command this way sequelize db:migrate when I needed to call the local installed package this way node_modules/.bin/sequelize db:migrate

Larry Cherry
  • 451
  • 1
  • 4
  • 11
13

i installed mysql2 package globally out of my project folder using :

npm install mysql2 -g
TECT 2000
  • 139
  • 1
  • 2
8

maybe I am late but for whoever looking for answer if and you have mysql2 installed just add this to your sequelize instance to direct sequelize to the right module:

dialectModule: require('mysql2'),

const sequelize = new Sequelize(config.db.database, config.db.user, config.db.password, {
  host: config.host,
  dialect:'mysql',
  dialectModule: require('mysql2'),
});

https://github.com/sequelize/sequelize/issues/9608

3
  1. List your global npm packages

    npm list -g --depth 0

  2. Uninstall sequelize

    npm uninstall -g sequelize

  3. Install sequelize in project scope

    npm install --save sequelize

BartusZak
  • 1,041
  • 14
  • 21
2

This worked for me:
npx sequelize-cli db:migrate

kazmi066
  • 573
  • 5
  • 15
1

You may have run npm install -g sequelize. You need to undo this using npm uninstall -g sequelize then use this npm install -g sequelize-cli instead. This worked for me.

1

I got this error while deploying my express app in vercel, below things helped me solve the error.

I have installed sequelize, sequelize-cli, and mysql2 locally, specific to the project.

npm install sequelize sequelize-cli mysql2 

Require the mysql2 package in the config file and add it to your configurations, attaching the image below for reference.

config.js

Hope it resolves!

Tyler2P
  • 2,324
  • 26
  • 22
  • 31
sanith_g
  • 11
  • 2
0

I was unable to call a specific instance of sequelize (local vs global), so I uninstalled the global sequelize that I had added through yarn yarn global remove sequelize and then added it locally to my project yarn add sequelize.

npm equivalents would be npm -g uninstall sequelize and npm install sequelize.

Note in case anyone is going through the same, I did have mysql2 installed.

Aurinxki
  • 111
  • 1
  • 6
0

Since version 5.2.0 nodejs comes alongside with an utility called npx, which is destined to be used as the "package runner", as it first look packages inside your node_modules you should not have any more troubles running commands with it.

NPM now should be used as a dependency manager instead of a command runner.

You can check differences of both here

xiscodev
  • 96
  • 1
  • 1
  • 5
0

I solved it by running :-

yarn add mysql2
Amera Abdallah
  • 638
  • 7
  • 5
  • Works nodejs 14LTS, just ensure you remove any mysql2 global npm installs, then install it with the above command or its equivalent `npm i mysql2` – briancollins081 Feb 24 '21 at 07:33
0

yarn add mysql2 or npm install mysql2

reboot your terminal

done!

Wellerson
  • 167
  • 1
  • 6
-1

The reason that you getting an error message to prompt you to install the mysql2 module is because of the db:migrate command is relied on the mysql2 but as an optionalDependencies, so you have to install the mysql2 module manually

Felix Fong
  • 969
  • 1
  • 8
  • 21
-1

If you are using Sequelize with Postgres then the issue will be in your config.json most likely because i ran into the same issue, in config.json my dialect was mysql and it was throwing an error so the correct one is

"development": {
    "username": "",
    "password": "",
    "database": "",
    "host": "127.0.0.1",
    "dialect": "postgres"
  },
-2

Did you try saving the config.json file before to run sequelize db:migrate? In my case that was the i

Doug
  • 1