Reputation: 4333
How to set collation for a specific Column in a Sequelize model?
I tried this:
name: {
type: Sequelize.STRING,
allowNull: false,
collate: 'utf8_general_ci'
},
Apparently it doesn't work. Any other ideia?
Upvotes: 10
Views: 5753
Reputation: 1
What It worked for me
await queryInterface.sequelize.query(`
ALTER TABLE files
MODIFY COLUMN original_name VARCHAR(255)
CHARACTER SET utf8mb4
COLLATE utf8mb4_general_ci NOT NULL;
`);
Upvotes: 0
Reputation: 778
There are several things you can do to support:
Table level:
sequlize.define('table', {
}, {
charset: 'utf8',
collate: 'utf8_general_ci'
})
Column level:
sequelize.define('table', {
column: Sequelize.STRING + ' CHARSET utf8 COLLATE utf8_general_ci'
})
Database level:
let sequelize = new Sequelize('database', {
dialectOptions: {
charset: 'utf8',
collate: 'utf8_general_ci',
}
});
Upvotes: 16