【发布时间】:2021-02-03 06:47:38
【问题描述】:
我正在尝试在 knex 迁移的 up 部分添加约束,然后在 down 部分中重新添加该约束(撤消更改)。我想保留表格及其所有列,但从其中一列中删除 unique 和 index 约束。这是我目前所拥有的:
exports.up = function(knex) {
return knex.schema
.table('menuItems', tbl => {
tbl.dropUnique("itemName")
tbl.dropIndex("itemName")
// ^these will leave the column but remove the constraints,
// correct?
});
};
exports.down = function(knex) {
// What do I do here?
};
假设在我当前的up 中,我确实只是删除了 constraint 而不是列,我的问题是:如何将约束添加回现有列(在 down ) 而不创建新列?
(我对 knex 迁移很不满意,而且我在网上找不到示例,所以如果有人有一些基本迁移的完整示例的链接,那也可能对我有所帮助。)
【问题讨论】:
标签: postgresql knex.js