How to Add, Delete new Columns in Sequelize CLI

后端 未结 7 1867
刺人心
刺人心 2020-12-07 16:43

I\'ve just started using Sequelize and Sequelize CLI

Since it\'s a development time, there are a frequent addition and deletion of columns. What the best the method

7条回答
  •  Happy的楠姐
    2020-12-07 17:21

    You can still use the sync function which takes an object parameter with two options of course a default option where you don't add a value and an instance where you add a force or an alter attribute. So in this case you want to use UserModel.sync({ force: true }): This creates the table, dropping it first if it already existed

    UserModel.sync({ alter: true })
    

    This checks what is the current state of the table in the database (which columns it has, what are their data types, etc), and then performs the necessary changes in the table to make it match the mode... You can use this when you use model instances For more info on updating and tables and models check out the docs on more functionality here

提交回复
热议问题