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
With migrations you can transfer your existing database into another state and vice versa: Those state transitions are saved in migration files, which describe how to get to the new state and how to revert the changes in order to get back to the old state. You will need the Sequelize Command-Line Interface (CLI).
-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
Please check in your database, table SequelizeMeta
, and remove record which corresponding name with file migration. Sequelize will log migration into this table, and when run migration again, it cannot re-run migration file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With