Cli: db:migration doesn't work using .sequelizerc

Created on 23 Sep 2017  路  3Comments  路  Source: sequelize/cli

What you are doing?

Hi All,
I'm trying to run a migration with my config defined to .sequelizrc but it throws me an Unhandled rejection TypeError using sequelize db:migrate command.

.sequelizerc
```const path = require('path');
const config = require(__dirname + '/config');
const cfg = {};
cfg[!process.env.NODE_ENV ? "development" : process.env.NODE_ENV] = config.MYSQL;
module.exports = {
'config': cfg,
'migrations-path': path.resolve(__dirname, 'sequelize/migrations'),
'seeders-path': path.resolve(__dirname, 'sequelize/seeders'),
'models-path': path.resolve(__dirname, 'models')
};

12345-migration file.js
```js
'use strict';
module.exports = {
    up: (queryInterface, Sequelize) => {
        return queryInterface.renameColumn('movement', 'timePerRep', 'timePerRepMillis');
    },
    down: (queryInterface, Sequelize) => {
        return queryInterface.renameColumn('movement', 'timePerRepMillis', 'timePerRep');
    }
};

What do you expect to happen?

I'm expecting that the migration will use the .sequezlizerc config file.

What is actually happening?

I believe that the CLI is reading the .sequelizerc but it is expecting a string instead of the config object.

Unhandled rejection TypeError: Path must be a string. Received { development: 
   { use_env_variable: false,
     sync: false,
     dialect: 'mysql',
     database: 'db_dev',
     host: '127.0.0.1',
     port: 3306,
     username: 'root',
     password: 'root' } }
    at assertPath (path.js:7:11)
    at Object.resolve (path.js:1153:7)
    at Object.getConfigFile (/usr/local/lib/node_modules/sequelize-cli/lib/helpers/config-helper.js:70:29)
    at Object.configFileExists (/usr/local/lib/node_modules/sequelize-cli/lib/helpers/config-helper.js:84:48)
    at /usr/local/lib/node_modules/sequelize-cli/lib/core/migrator.js:58:34
From previous event:
    at getMigrator (/usr/local/lib/node_modules/sequelize-cli/lib/core/migrator.js:57:32)
    at migrate (/usr/local/lib/node_modules/sequelize-cli/lib/commands/migrate.js:50:36)
    at Object.<anonymous> (/usr/local/lib/node_modules/sequelize-cli/lib/commands/migrate.js:31:15)
    at next (native)
    at runCallback (timers.js:672:20)
    at tryOnImmediate (timers.js:645:5)
    at processImmediate [as _immediateCallback] (timers.js:617:5)
From previous event:
    at Object.handler (/usr/local/lib/node_modules/sequelize-cli/lib/commands/migrate.js:45:17)
    at Object.self.runCommand (/usr/local/lib/node_modules/sequelize-cli/node_modules/yargs/lib/command.js:233:22)
    at Object.Yargs.self._parseArgs (/usr/local/lib/node_modules/sequelize-cli/node_modules/yargs/yargs.js:990:30)
    at Object.get [as argv] (/usr/local/lib/node_modules/sequelize-cli/node_modules/yargs/yargs.js:927:19)
    at Object.<anonymous> (/usr/local/lib/node_modules/sequelize-cli/lib/sequelize:80:15)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.runMain (module.js:604:10)
    at run (bootstrap_node.js:389:7)
    at startup (bootstrap_node.js:149:9)
    at bootstrap_node.js:502:3

__Dialect:mysql
__Database version:5.6.24
__Sequelize CLI version:3.0.0-2
__Sequelize version:4.8.4

question

Most helpful comment

Have same issue with 4.0.0 version of cli.
Same error appears even if I provide string path to cli - I tried to use config.js file, but cli can't.
And same config.json file works :/

All 3 comments

'config': cfg, should be a path to file not configuration itself.

See http://docs.sequelizejs.com/manual/tutorial/migrations.html#dynamic-configuration this is how you can create a file which can return dynamic configuration. give that dynamic config file's path in .sequelizerc file

'config': cfg, should be a path to file not configuration itself.

This solution works! Thanks a lot, @sushantdhiman.

Have same issue with 4.0.0 version of cli.
Same error appears even if I provide string path to cli - I tried to use config.js file, but cli can't.
And same config.json file works :/

Was this page helpful?
0 / 5 - 0 ratings