node.js - How to create a Sequelize cli db migration after changes to the model -


i starting sequelize , following video tutorial online. after running

node_modules/.bin/sequelize model:create --name user --attributes username:string  node_modules/.bin/sequelize model:create --name task --attributes title:string 

which created migration files create user , create task. had add associations each model follow:

// user.js classmethods: {   associate: function(models) {     user.hasmany(models.task);   } }  // task.js classmethods: {   associate: function(models) {     task.belongsto(models.user);   } } 

however, migration files creating tables user , task created. have manually update them add relationships? "migration:create" command creates migration skeleton file. manually fill out skeleton files or there way automatically create complete migration file besides model creation?

p.s have seen following stackoverflow question: how auto generate migrations sequelize cli sequelize models?

you can create separate migration empty migration file. did when needed add few columns table.

sequelize migration:create --name users 

then in new migration file.

module.exports = {   up: function (queryinterface, sequelize) {     queryinterface.addcolumn(       'users',       'url',       sequelize.string     );   },    down: function (queryinterface, sequelize) {     queryinterface.removecolumn(       'users',       'url',       sequelize.string     );   } }; 

then run migrations.

sequelize db:migrate 

Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -