I am trying to modify the column data-type from date to timestamp in migration script using below code
knex.schema.alterTable('user', function(t) {
t.timestamp('bifthday_date').alter();
});
Error : Knex:warning - migrations failed with error: table.timestamp(...).alter is not a function
In the year's since this was first answered, it appears that Knex.js 0.21.15 (possibly earlier but don't know from when) will handle an alter column from date to timestamp, this is the code that I used:
exports.up = async function(knex, Promise) {
await knex.schema.alterTable('campaigns', function(table) {
table.timestamp('intake_start_date').alter();
table.timestamp('intake_end_date').alter();
});
}
Note that in the knex alter
documentation:
Marks the column as an alter / modify, instead of the default add. Note: This only works in .alterTable() and is not supported by SQlite or Amazon Redshift.
I have managed to modify data-type using knex raw query.
knex.raw('alter TABLE user ALTER COLUMN birthday_date TYPE timestamp with time zone');
I would assume that this failed because you tried to call a column by the name of "bifthday_date" as opposed to "birthday_date", which you used successfully later in your own answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With