How to recreate database from old database using sequelize in node.js(如何使用 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:
- 正如您所说,重新创建数据库,但这会删除表(删除您的数据).
- 使用迁移(您可以阅读这里)
迁移允许您不丢失数据并指导 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 从旧数据库重新创建数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使用 node.js 中的 sequelize 从旧数据库重新创建数据库
基础教程推荐
- 二进制文件到 SQL 数据库 Apache Camel 2021-01-01
- 什么是 orradiag_<user>文件夹? 2022-01-01
- 如何根据该 XML 中的值更新 SQL 中的 XML 2021-01-01
- 在多列上分布任意行 2021-01-01
- 如何在 SQL 中将 Float 转换为 Varchar 2021-01-01
- mysql选择动态行值作为列名,另一列作为值 2021-01-01
- 在 MySQL 中:如何将表名作为存储过程和/或函数参数传递? 2021-01-01
- MySQL 中的类型:BigInt(20) 与 Int(20) 2021-01-01
- oracle区分大小写的原因? 2021-01-01
- 表 './mysql/proc' 被标记为崩溃,应该修复 2022-01-01
