如何使用 node.js 中的 sequelize 从旧数据库重新创建数据库 [英] How to recreate database from old database using sequelize in node.js

查看:52
本文介绍了如何使用 node.js 中的 sequelize 从旧数据库重新创建数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

推荐答案

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

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

  1. 正如您所说,重新创建数据库,但这会删除表(删除您的数据).
  2. 使用迁移(您可以阅读这里)

迁移允许您不丢失数据并指导 sequelize 如何更改表.

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 从旧数据库重新创建数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆