node.jsormsequelize.js

How to set collation for a specific Column in a Sequelize model?


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?


Solution

  • 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',
        }
    });