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

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

问题描述

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

解决方案

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

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

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

此处

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:

  1. as you said recreate db, but this will drop tables (erase your data).
  2. 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从旧数据库重新创建数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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