Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

db:makemigrations not working #82

Open
osvaldokalvaitir opened this issue Aug 10, 2020 · 6 comments
Open

db:makemigrations not working #82

osvaldokalvaitir opened this issue Aug 10, 2020 · 6 comments

Comments

@osvaldokalvaitir
Copy link

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.

@ericbenedetto16
Copy link

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.

@osvaldokalvaitir
Copy link
Author

Eric!
you're right, I forgot to put node, I remember that I had done a test here, but this error occurred:

image

It looks like he can't find my folder, or can't find the models! But there are 4 in the folder.

@ericbenedetto16
Copy link

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)

@osvaldokalvaitir
Copy link
Author

Eric, yes, I have!

image

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?

@ericbenedetto16
Copy link

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!

@osvaldokalvaitir
Copy link
Author

I have the 'database' file similar to yours, but in the 'index' I commented out the 'env' code.

image

Is working if my models are passed like this:
image

but if I do it like this:

import { Models } from 'sequelize';

doesn't work, so I think the package doesn't support ESM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants