Open osvaldokalvaitir opened 4 years ago
Make sure you are running the file, not just opening it from the terminal.
Try node ./node_modules/sequelize-auto-migrations/bin/makemigration.js
in your package.json instead so it is being run.
Eric! you're right, I forgot to put node, I remember that I had done a test here, but this error occurred:
It looks like he can't find my folder, or can't find the models! But there are 4 in the folder.
Do you have an index.js file in the models directory that imports all of the models? (if you ran sequelize init
there should be one for you)
Eric, yes, I have!
I had no index in the model folder. Delete my 'database' file and it generated both.
Thank you very much, Eric !! Everything worked.
I know it has nothing to do with this issue, but he didn't accept the 'imports' I have on the models, is this library supported?
Seems like a dead repo, but what I did earlier since my imports weren't working was I forked the repo and made it so I can pass my connection in the CLI. Check it out Here
How I used it was when I instantiate and export my db connection:
config/db.js
const Sequelize = require('sequelize');
module.exports = new Sequelize(
process.env.DB_DATABASE,
process.env.DB_USER,
process.env.DB_PASS,
{
host: process.env.DB_HOST,
dialect: 'mysql',
operatorAliases: false,
define: {
timestamps: false,
},
pool: {
max: 5,
min: 0,
acquire: 30000,
idle: 10000,
},
}
);
Then in my models directory I left index.js completely empty.
Lastly, in the command inside your package.json you can use "db:makemigrations": "node ./node_modules/sequelize-auto-migrations/bin/makemigration.js --conn ./config/db.js"
Let me know if this helps!
I have the 'database' file similar to yours, but in the 'index' I commented out the 'env' code.
Is working if my models are passed like this:
but if I do it like this:
import { Models } from 'sequelize';
doesn't work, so I think the package doesn't support ESM.
I read a tutorial on how to use, installing:
npm install --save github:scimonster/sequelize-auto-migrations#a063aa6535a3f580623581bf866cef2d609531ba
Edit package.json "scripts": { ... "db:makemigrations": "./node_modules/sequelize-auto-migrations/bin/makemigration.js", }
After: npm run db:makemigrations
But when running, nothing happens, just open the file 'makemigration.js'.
I have a .sequelizerc file:
const { resolve } = require('path');
module.exports = { config: resolve(dirname, 'src', 'config', 'database.js'), 'models-path': resolve(dirname, 'src', 'app', 'models'), 'migrations-path': resolve(dirname, 'src', 'database', 'migrations'), 'seeders-path': resolve(dirname, 'src', 'database', 'seeds'), };
Could that be it? if anyone can help me, i will be very grateful.