knex: knex migration doesn't find the config file
Environment
Knex version: 0.16.2 Database + version: postgres 11 OS: mac os 10.13.6
Select applicable tempalate from below. If issue is about oracledb support tag @ atiertant. For MSSql tag @ smorey2 . Rest of dialects doesn’t need tags.
Bug
- Explain what kind of behaviour you are getting and how you think it should do
the knex config file: /tools/knex/knex.js
require('dotenv').config()
const connection = {
host: process.env.PGHOST,
port: process.env.PGPORT,
database: process.env.PGDATABASE,
user: process.env.PGUSER,
password: process.env.PGPASSWORD
}
const knexConfig = {
client: 'pg',
connection,
migrations: {
directory: './tools/knex/migrations'
},
seeds: {
directory: './tools/knex/seeds'
}
}
module.exports = knexConfig
when I run npx knex --knexfile=./tools/knex/config.js migrate:rollback,
it makes an error Error: ENOENT: no such file or directory, scandir '/Volumes/HD/Documents/my-app/migrations'
from the config file it should look for migrations in ./tools/knex/migrations and not in ./migrations
This was working well in previous knex version 0.15.2
About this issue
- Original URL
- State: open
- Created 6 years ago
- Reactions: 5
- Comments: 24 (3 by maintainers)
Commits related to this issue
- revert: bug avec la mise à jour de knex https://github.com/tgriesser/knex/issues/2952 — committed to MTES-MCT/camino-api by francoisromain 6 years ago
- revert: bug avec la mise à jour de knex https://github.com/tgriesser/knex/issues/2952 — committed to risseraka/camino-api by francoisromain 6 years ago
- revert: bug avec la mise à jour de knex https://github.com/tgriesser/knex/issues/2952 — committed to MTES-MCT/camino-api by francoisromain 6 years ago
0.16.3 is out with a fix for this.
Probably didn’t do a npx knex init. Solved problem for me
Hello @kibertoad I run the command from the root of the project with
npx knex --knexfile=./tools/knex/config.js migrate:rollback. The config file is located at./tools/knex/knex.jsand the migrations are at./tools/knex/migrations.The error says it look for the migrations directory at its default place (
./migrations), while the config file indicates it’s located at./tools/knex/migrations.So my guess is it didn’t find the config file.
You can find this project here: https://github.com/MTES-MCT/camino-api, currently working with this conf and knex 0.15.2 and bugging on 0.16.2.
thank you
@stf8 I’ll try to address it this week.
Hell yeah, one more edgecase 😄. @elhigu Do you think we should modify non-CLI migrations to behave like CLI migrations in this case? Alternatively we may try to strictly reconstruct 0.15.x behavior, but considering that it wasn’t documented nor covered with tests…
This change actually broke the builds for us. We use
knexfile.jsin different places (code and npm scripts), e.g.:It worked properly prior to v 16.3 where both would expect path relative to current dir, but after 16.3 upgrade, now one expects a relative path to current directory and the other one relative to
knexfile.jslocation. Not sure how to make them both happy now w/o creating symlinks.