2
我正在使用knex js和postgresql數據庫。我用遷移文件創建了一張表knex migrate:make create_car_table
。在這個我添加了一個列fuel_type。 table.enu('fuel_type', ['PETROL', 'DIESEL', 'CNG'])
。修改PostgreSQL的Knex js中的表修改枚舉給出錯誤
現在我需要改變表格,我需要這些枚舉值['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。
感謝@mikael我改變了約束名稱,它的工作。 –