you should know the data type. for e.g. STRING
:
const { DataTypes } = require('sequelize');
return queryInterface.changeColumn('Table', 'attributeName', {
defaultValue: null,
type: DataTypes.STRING
});
you can also use queryInterface
from the model
definition (or pass the model/query interface) to make it generic for any column with default value:
function dropDefaults(queryInterface, model) {
const defaultValues = Object.keys(model._defaultValues);
for (const column of defaultValues) {
model.queryInterface.changeColumn(model.tableName, column, {
defaultValue: null,
type: model.fieldRawAttributesMap[column].type,
});
}
}