防止续集删除 node.js 应用程序中的数据库

编程入门 行业动态 更新时间:2024-10-26 06:27:35
本文介绍了防止续集删除 node.js 应用程序中的数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

首先,我使用的是 node.js 和 sequelize ORM 和 Postgres SQL.

First of all, I am using node.js with sequelize ORM and Postgres SQL.

我有两个简单的问题:

  • 每次我重新运行我的节点应用程序时,sequelize 都会删除并创建数据库中的所有表.如何防止它这样做(我不希望我在数据库中的记录被删除)?我尝试将我的 NODE_ENV 设置为测试,但没有帮助.

  • Every time I rerun my node application sequelize is dropping and creating all tables in database. How to prevent it from doing that (I don't want my records in database to be deleted)? I have tried to set my NODE_ENV to test but it didn't help.

    sequelize 迁移如何知道它在哪里停止(哪些迁移已执行,哪些未执行).例如,当我在 Grails 框架中使用数据库迁移时,它会自动在数据库中创建一个表,其中保存了之前执行的所有迁移时间戳,当我重新运行我的应用程序时,它会查看该表并知道哪些迁移已经完成以及哪些不是.使用节点/续集时我没有看到任何表,那么它是如何工作的?:)

    How does sequelize migration knows where it stopped (which migration have executed and which not). When I was using database migration in Grails framework, for example, it automatically created a table in the database where it kept all migration timestamps that executed before and when I rerun my application it looks at that table and knows which migrations are already done and which are not. I don't see any table when using node/sequelize, so how it works? :)

    谢谢,伊万

    推荐答案

    如你所见,表被删除是因为你在做

    As you already figured out, the tables are being dropped because you are doing

    sequelize.sync({ force: true })

    原力为真部分是罪魁祸首

    The force true part being the culprit

    关于你的第二个问题 - 迁移状态保存在你的数据库中的一个表中 - 我相信它被称为 sequelize_meta

    To your second question - the state of migrations is saved in a table in your db - i believe it's called sequelize_meta

  • 更多推荐

    防止续集删除 node.js 应用程序中的数据库

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

    发布评论

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

    >www.elefans.com

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