首先,我使用的是 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 应用程序中的数据库
发布评论