I am using knex js and postgresql database. I have used a migration file to create a table knex migrate:make create_car_table
. In this I have added a column fuel_type. table.enu('fuel_type', ['PETROL', 'DIESEL', 'CNG'])
.
Now I need to alter the table and I need these enum values ['HYBRID', 'ELECTRIC', 'PETROL', 'DIESEL']
.
I have created another migration file using knex migrate:make alter_car_table
and added the below code
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();
});
};
when I run knex migrate:latest
I get the below error.
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"
I have refered Knex Js for this.