1. <i id='GrrM7'><tr id='GrrM7'><dt id='GrrM7'><q id='GrrM7'><span id='GrrM7'><b id='GrrM7'><form id='GrrM7'><ins id='GrrM7'></ins><ul id='GrrM7'></ul><sub id='GrrM7'></sub></form><legend id='GrrM7'></legend><bdo id='GrrM7'><pre id='GrrM7'><center id='GrrM7'></center></pre></bdo></b><th id='GrrM7'></th></span></q></dt></tr></i><div id='GrrM7'><tfoot id='GrrM7'></tfoot><dl id='GrrM7'><fieldset id='GrrM7'></fieldset></dl></div>

      2. <legend id='GrrM7'><style id='GrrM7'><dir id='GrrM7'><q id='GrrM7'></q></dir></style></legend>
          <bdo id='GrrM7'></bdo><ul id='GrrM7'></ul>
      3. <tfoot id='GrrM7'></tfoot>
      4. <small id='GrrM7'></small><noframes id='GrrM7'>

      5. Sequelize:在生产中更改模型架构

        时间:2023-09-03
        • <bdo id='1cHBu'></bdo><ul id='1cHBu'></ul>
          <tfoot id='1cHBu'></tfoot>

              <tbody id='1cHBu'></tbody>

                • <small id='1cHBu'></small><noframes id='1cHBu'>

                  <legend id='1cHBu'><style id='1cHBu'><dir id='1cHBu'><q id='1cHBu'></q></dir></style></legend>
                  <i id='1cHBu'><tr id='1cHBu'><dt id='1cHBu'><q id='1cHBu'><span id='1cHBu'><b id='1cHBu'><form id='1cHBu'><ins id='1cHBu'></ins><ul id='1cHBu'></ul><sub id='1cHBu'></sub></form><legend id='1cHBu'></legend><bdo id='1cHBu'><pre id='1cHBu'><center id='1cHBu'></center></pre></bdo></b><th id='1cHBu'></th></span></q></dt></tr></i><div id='1cHBu'><tfoot id='1cHBu'></tfoot><dl id='1cHBu'><fieldset id='1cHBu'></fieldset></dl></div>

                  本文介绍了Sequelize:在生产中更改模型架构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我们正在使用 orm sequelize.js 并定义了这样的模型:

                  We're using the orm sequelize.js and have defined a model as such:

                  module.exports = function(sequelize, DataTypes) {
                      var Source = sequelize.define('Source', {
                          name: {
                              type: DataTypes.STRING, 
                              allowNull: false, 
                              unique: true
                          }
                      }, {
                          paranoid: true
                      });
                  
                      return Source;
                  };
                  

                  这被部署到生产环境并使用 sequelize.sync 同步到数据库.下一步,我们添加一个参数:

                  This is deployed to production and sync'd to the database using sequelize.sync. Next step, we add a parameter:

                  module.exports = function(sequelize, DataTypes) {
                      var Source = sequelize.define('Source', {
                          name: {
                              type: DataTypes.STRING, 
                              allowNull: false, 
                              unique: true
                          }, 
                              location: {
                                      type: DataTypes.STRING
                              }
                      }, {
                          paranoid: true
                      });
                  
                      return Source;
                  };
                  

                  但是,当部署到生产环境时,sequelize.sync 不会添加这个新参数.这是因为 sync 做了一个:

                  However, when deploying to production sequelize.sync does not add this new parameter. This is because sync does a:

                  如果不存在则创建表

                  如果表存在,则实际上不会更新架构.这是在他们的文档中注明的.

                  And does not actually update the schema if the table exists. This is noted in their documentation.

                  唯一的选择似乎是 { force: true },但这对于生产数据库来说是不行的.

                  The only option seems to be to { force: true }, however this is not okay for a production database.

                  有谁知道在需要更改时如何正确更新架构?

                  Does anyone know how to properly update the schema when changes are necessary?

                  推荐答案

                  你想实现 Sequelize 迁移:

                  You want to implement Sequelize migrations:

                  http://docs.sequelizejs.com/manual/tutorial/migrations.html

                  这些将使您能够在已知状态之间转换开发人员、暂存和生产数据库.

                  These will enable you to transition developer, staging, and production databases between known states.

                  这篇关于Sequelize:在生产中更改模型架构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:续集如何检查数据库中是否存在条目 下一篇:复数如何在 Sequelize 中工作?

                  相关文章

                  1. <small id='SPhiP'></small><noframes id='SPhiP'>

                    <tfoot id='SPhiP'></tfoot>
                  2. <legend id='SPhiP'><style id='SPhiP'><dir id='SPhiP'><q id='SPhiP'></q></dir></style></legend>
                      <bdo id='SPhiP'></bdo><ul id='SPhiP'></ul>

                    <i id='SPhiP'><tr id='SPhiP'><dt id='SPhiP'><q id='SPhiP'><span id='SPhiP'><b id='SPhiP'><form id='SPhiP'><ins id='SPhiP'></ins><ul id='SPhiP'></ul><sub id='SPhiP'></sub></form><legend id='SPhiP'></legend><bdo id='SPhiP'><pre id='SPhiP'><center id='SPhiP'></center></pre></bdo></b><th id='SPhiP'></th></span></q></dt></tr></i><div id='SPhiP'><tfoot id='SPhiP'></tfoot><dl id='SPhiP'><fieldset id='SPhiP'></fieldset></dl></div>