【问题标题】:How to index timestamp type with knexjs如何使用 knexjs 索引时间戳类型
【发布时间】:2021-12-08 23:04:43
【问题描述】:

我正在尝试使用 knex js 索引 created_at 和 updated_at 列 但是当我分配 index() 时,它显示了这个错误:

类型“void”上不存在属性“index”

await knex.schema.createTable('ontario_user_reports', (table) => {
    table.string('user_id').notNullable().index();
    table.timestamps(false, true).index(); // here
    table.string('type').notNullable().index();
});

你能给我一个正确的方法来索引 created_at 吗?

【问题讨论】:

    标签: javascript node.js typescript postgresql knex.js


    【解决方案1】:

    您应该可以像这样添加索引:

    await knex.schema.createTable('ontario_user_reports', (table) => {
        table.string('user_id').notNullable().index();
        table.timestamps(false, true);
        table.string('type').notNullable().index();
    
        // Add this line:
        table.index('created_at');
    });
    

    或者,使用此处所述的参数设置名称和其他选项:https://knexjs.org/#Schema-index

    【讨论】:

      猜你喜欢
      • 2017-07-07
      • 2018-10-07
      • 2012-05-23
      • 1970-01-01
      • 2012-09-15
      • 2017-09-04
      • 1970-01-01
      • 1970-01-01
      • 2019-09-09
      相关资源
      最近更新 更多