I've two models:
user.js
'use strict'
module.exports = function(sequelize, DataTypes) {
var User = sequelize.define('User', {
gid: {
type: DataTypes.INTEGER,
allowNull: false,
primaryKey: true,
autoIncrement: true
},
email: {
type: DataTypes.STRING,
allowNull: false
},
password: {
type: DataTypes.STRING,
allowNull: false
},
newsletters: {
type: 'NUMERIC',
allowNull: false,
defaultValue: '1'
},
status: {
type: 'NUMERIC',
allowNull: false,
defaultValue: '1'
},
date_verified: {
type: DataTypes.TIME,
allowNull: true
},
date_created: {
type: DataTypes.TIME,
allowNull: false,
defaultValue: sequelize.fn('now')
},
date_updated: {
type: DataTypes.TIME,
allowNull: false,
defaultValue: sequelize.fn('now')
}
},{
tableName: 'user'
},{
classMethods:{
associate: function(models){
User.belongsTo(models.User);
}
}
});
User.schema("security");
return User;
};
role.js
'use strict'
module.exports = function(sequelize, DataTypes) {
var Role = sequelize.define('Role', {
gid: {
type: DataTypes.INTEGER,
allowNull: false,
primaryKey: true,
autoIncrement: true
},
name: {
type: DataTypes.STRING,
allowNull: false
},
status: {
type: 'NUMERIC',
allowNull: false,
defaultValue: '1'
},
date_created: {
type: DataTypes.TIME,
allowNull: false,
defaultValue: sequelize.fn('now')
},
date_updated: {
type: DataTypes.TIME,
allowNull: false,
defaultValue: sequelize.fn('now')
}
},{
tableName: 'role'
},{
classMethods:{
associate: function(models){
Role.hasMany(models.User);
}
}
});
Role.schema("security");
return Role;
};
And index.js in the same "models" folder, that is generated automatically for Sequelize.
I only changed the config.json with my connection variables, and connects succefully.
But, when I put in console
node_modules/.bin/sequelize db:migrate
Shows me this:
Sequelize [Node: 4.4.4, CLI: 2.1.0, ORM: 3.12.2, pg: ^4.4.3]
Loaded configuration file "config\config.json".
Using environment "development".
Using gulpfile c:\Users\Ulises\MVO-app\server\node_modules\sequelize-cli\lib\gulpfile.js
Starting 'db:migrate'...
Finished 'db:migrate' after 180 ms
No migrations were executed, database schema was already up to date.
And in my DB don't create the models
-This worked for me-
In your database, please find the table named 'SequelizeMeta' and remove the relevant record you want to migrate.
After that run this on your console.
$ npx sequelize-cli db:migrate