代码之家  ›  专栏  ›  技术社区  ›  Robert Wildling

knex:如何在Directus 10中重命名许多现有的表?

  •  0
  • Robert Wildling  · 技术社区  · 1 年前

    我在现有的(TYPO3)项目上安装了Directus 10,现在想重命名表。为此,Directus文档建议创建一个迁移,我就是这么做的。有一个助手文件,它包含一个常量,其中包含一个新旧表名的数组,如下所示:

    const { $renameTablesString } = [
         { origName: "tx_rwfm_domain_model_address_addresscategory_mm", 
           newName: "rwfm_mm_address_addresscategory;"},
    
         { origName: "tx_rwfm_domain_model_address_location_mm", 
           newName: "rwfm_mm_address_location;"},
    
         { origName: "tx_rwfm_domain_model_address_person_mm", 
           newName: "rwfm_mm_address_person;"},
    
         ...
    ]
    
    

    该文件被导入到迁移文件中,然后在 up Directus需要使用的函数:

    import { $renameTablesString } from '../utils/rename-tables'
    
    // Rename all tables
    export async function up(knex) {
        $renameTablesString.forEach(async item => {
            await knex.schema
                .renameTable(item.orig, item.newitem)
                .dropTable(item.orig);
        })
    };
    

    运行时 npx directus database migrate:up 2023-06-23__002__rename-tables.js (从本地Docker实例中)我收到以下错误消息:

    迁移密钥冲突! 请确保每次迁移都使用唯一的密钥。

    问题

    • 为什么会发生这种情况?
    • 我必须适应什么才能使迁移工作?
    0 回复  |  直到 1 年前