【问题标题】:Typeorm, how to handle deleted entities when running migrationsTypeorm,运行迁移时如何处理已删除的实体
【发布时间】:2021-07-02 17:24:13
【问题描述】:

我的项目有一个删除实体的重构,但是,当我尝试通过typeorm migration:run 运行新迁移时,我从初始迁移(已经运行的迁移)中收到打字稿错误,因为我不再拥有它正在导入的实体。

src/migrations/1603278044988-defaultEntity.ts:3:20 - error TS2307: Cannot find module '../entities/entity' or its corresponding type declarations.

3 import Entity from '../entities/entity';

与此同时,src/migrations/1603278044988-defaultEntity.ts 不久前在我的数据库中运行并注册。

我最初的感觉是直接在我的 tsconfig 中排除我的迁移,但这并没有导致任何不同的结果。如果没有 ts 检查或隔离一个迁移文件,我也看不到一种运行迁移的方法。

TYPEORM_SYNCHRONIZEFalse

【问题讨论】:

    标签: typescript migration typeorm


    【解决方案1】:

    我意识到以前的迁移不应该使用任何“源”代码,应该用原始插入替换它们。

    在最坏的情况下,我可以将它们内联移动到迁移中或作为专门针对它们的导入,而不是删除实体。

    【讨论】:

      猜你喜欢
      • 2020-10-30
      • 1970-01-01
      • 2022-07-02
      • 2021-05-23
      • 1970-01-01
      • 1970-01-01
      • 2022-01-11
      • 2021-10-17
      • 1970-01-01
      相关资源
      最近更新 更多