如何在node.js中使用sequelize从旧数据库重新创建数据库

编程入门 行业动态 更新时间:2024-10-27 02:18:49
本文介绍了如何在node.js中使用sequelize从旧数据库重新创建数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在我保持 {force:true} 的同时,我遇到了 sequelize 的一些问题.在这种情况下,旧数据将被删除,新数据库将被创建,而我保存的数据将丢失.我想用旧值创建新数据库.使用node.js中的 sequelize 可以做到这一点

解决方案

当您的数据库中有一些数据并且想要在db中进行某些更改时,您有两种可能性:

  • 正如您所说的,重新创建数据库,但这将删除表(擦除您的数据).
  • 使用迁移(您可以在此处上了解)
  • >

    迁移使您可以不丢失数据并指示后续如何更改表.

    此处 I am facing some problem with sequelize while i keep {force: true} . In this case old data dropped and new database is created and my saved data get lost. I want to create new database with old values. Can that possible with sequelize in node.js

    解决方案

    When you have database with some data and want to make some changes in db you have two possibilities:

  • as you said recreate db, but this will drop tables (erase your data).
  • use migrations (you can read about it here)
  • Migrations allow you to to don't loose your data and instruct sequelize how to change tables.

    There is ticket for recreating tables with alter tables instead of drop tables here

    更多推荐

    如何在node.js中使用sequelize从旧数据库重新创建数据库

    本文发布于:2023-10-19 00:04:48,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1505822.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:数据库   如何在   js   node   sequelize

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!