【发布时间】:2023-03-20 03:59:01
【问题描述】:
我正在使用 knex js 和 postgresql 数据库。我使用迁移文件创建了一个表knex migrate:make create_car_table。在此我添加了一个列fuel_type。 table.enu('fuel_type', ['PETROL', 'DIESEL', 'CNG']).
现在我需要修改表,我需要这些枚举值['HYBRID', 'ELECTRIC', 'PETROL', 'DIESEL']。
我使用knex migrate:make alter_car_table 创建了另一个迁移文件并添加了以下代码
exports.up = function(knex, Promise) {
return knex.schema.alterTable('car', function (table) {
table.enu('fuel_type', ['HYBRID', 'ELECTRIC', 'PETROL', 'DIESEL']).alter();
});
};
exports.down = function(knex, Promise) {
return knex.schema.alterTable('car', function (table) {
table.enu('fuel_type', ['PETROL', 'DIESEL', 'CNG']).alter();
});
};
当我运行 knex migrate:latest 时,出现以下错误。
Knex:warning - migrations failed with error: alter table "car" alter column "fuel_type" type text check ("fuel_type" in ('HYBRID', 'ELECTRIC', 'PETROL', 'DIESEL')) using ("fuel_type"::text check ("fuel_type" in ('HYBRID', 'ELECTRIC', 'PETROL', 'DIESEL'))) - syntax error at or near "check"
我已经为此推荐了Knex Js。
【问题讨论】:
标签: enums knex.js postgresql-9.5