Im using sequelize /w node and node-mysql.
I create models using the sequelize-cli, and this is the result:
'use strict';
module.exports = function(sequelize, DataTypes) {
let songs = sequelize.define('songs', {
name: DataTypes.STRING,
link: DataTypes.STRING,
artist: DataTypes.STRING,
lyrics: DataTypes.TEXT,
writer: DataTypes.STRING,
composer: DataTypes.STRING
});
return songs;
};
I want to be able to define collation and charset to each property of the model. the default collation is 'latin1_swedish_ci', and i need it in 'utf-8'.
Anyone? Tnx
Models can be defined in two equivalent ways in Sequelize: Calling sequelize. define(modelName, attributes, options) Extending Model and calling init(attributes, options)
When you create a Sequelize model, you can add the default value for your model by adding the defaultValue option to the column(s) definition. The defaultValue option will be used by Sequelize to define default value(s) for your SQL column(s) when you create a table using Sequelize.
Using the Sequelize hasOne() association method. The Sequelize hasOne() association method is used to establish an association between two defined Sequelize models. The association method allows you to link two models so that you can retrieve data from both tables with one query execution.
In the part where u define sequelize
var sequelize = new Sequelize('database', 'username', 'password', {
define: {
charset: 'utf8',
collate: 'utf8_general_ci',
timestamps: true
},
logging:false
});
For Table level Changing
sequelize.define('songs', {
name: DataTypes.STRING,
link: DataTypes.STRING,
artist: DataTypes.STRING,
lyrics: DataTypes.TEXT,
writer: DataTypes.STRING,
composer: DataTypes.STRING
}, {
charset: 'utf8',
collate: 'utf8_unicode_ci'
});
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