Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
Model options.charset is overwritten by default options #12273
Comments
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
|
I can confirm this bug on const Sequelize = require("./index");
const sequelize = require("./test/support").createSequelizeInstance({
charset: "utf8",
});
const Model = Sequelize.Model;
(async () => {
const User = sequelize.define(
"User",
{
name: Sequelize.STRING,
},
{
charset: "utf8mb4",
collate: "utf8mb4_general_ci",
}
);
await sequelize.sync({
force: true,
});
})();DatabaseError [SequelizeDatabaseError]: COLLATION 'utf8mb4_general_ci' is not valid for CHARACTER SET 'utf8'
at Query.formatError (/var/projects/oss/sequelize/lib/dialects/mysql/query.js:239:16)
at Query.handler [as onResult] (/var/projects/oss/sequelize/lib/dialects/mysql/query.js:50:23)
at Query.execute (/var/projects/oss/sequelize/node_modules/mysql2/lib/commands/command.js:30:14)
at Connection.handlePacket (/var/projects/oss/sequelize/node_modules/mysql2/lib/connection.js:408:32)
at PacketParser.onPacket (/var/projects/oss/sequelize/node_modules/mysql2/lib/connection.js:70:12)
at PacketParser.executeStart (/var/projects/oss/sequelize/node_modules/mysql2/lib/packet_parser.js:75:16)
at Socket.<anonymous> (/var/projects/oss/sequelize/node_modules/mysql2/lib/connection.js:77:25)
at Socket.emit (events.js:311:20)
at addChunk (_stream_readable.js:294:12)
at readableAddChunk (_stream_readable.js:275:11) {
name: 'SequelizeDatabaseError',
parent: Error: COLLATION 'utf8mb4_general_ci' is not valid for CHARACTER SET 'utf8'
at Packet.asError (/var/projects/oss/sequelize/node_modules/mysql2/lib/packets/packet.js:708:17)
at Query.execute (/var/projects/oss/sequelize/node_modules/mysql2/lib/commands/command.js:28:26)
at Connection.handlePacket (/var/projects/oss/sequelize/node_modules/mysql2/lib/connection.js:408:32)
at PacketParser.onPacket (/var/projects/oss/sequelize/node_modules/mysql2/lib/connection.js:70:12)
at PacketParser.executeStart (/var/projects/oss/sequelize/node_modules/mysql2/lib/packet_parser.js:75:16)
at Socket.<anonymous> (/var/projects/oss/sequelize/node_modules/mysql2/lib/connection.js:77:25)
at Socket.emit (events.js:311:20)
at addChunk (_stream_readable.js:294:12)
at readableAddChunk (_stream_readable.js:275:11)
at Socket.Readable.push (_stream_readable.js:209:10) {
code: 'ER_COLLATION_CHARSET_MISMATCH',
errno: 1253,
sqlState: '42000',
sqlMessage: "COLLATION 'utf8mb4_general_ci' is not valid for CHARACTER SET 'utf8'",
sql: 'CREATE TABLE IF NOT EXISTS `Users` (`id` INTEGER NOT NULL auto_increment , `name` VARCHAR(255), `createdAt` DATETIME NOT NULL, `updatedAt` DATETIME NOT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE utf8mb4_general_ci;',
parameters: undefined
},
original: Error: COLLATION 'utf8mb4_general_ci' is not valid for CHARACTER SET 'utf8'
at Packet.asError (/var/projects/oss/sequelize/node_modules/mysql2/lib/packets/packet.js:708:17)
at Query.execute (/var/projects/oss/sequelize/node_modules/mysql2/lib/commands/command.js:28:26)
at Connection.handlePacket (/var/projects/oss/sequelize/node_modules/mysql2/lib/connection.js:408:32)
at PacketParser.onPacket (/var/projects/oss/sequelize/node_modules/mysql2/lib/connection.js:70:12)
at PacketParser.executeStart (/var/projects/oss/sequelize/node_modules/mysql2/lib/packet_parser.js:75:16)
at Socket.<anonymous> (/var/projects/oss/sequelize/node_modules/mysql2/lib/connection.js:77:25)
at Socket.emit (events.js:311:20)
at addChunk (_stream_readable.js:294:12)
at readableAddChunk (_stream_readable.js:275:11)
at Socket.Readable.push (_stream_readable.js:209:10) {
code: 'ER_COLLATION_CHARSET_MISMATCH',
errno: 1253,
sqlState: '42000',
sqlMessage: "COLLATION 'utf8mb4_general_ci' is not valid for CHARACTER SET 'utf8'",
sql: 'CREATE TABLE IF NOT EXISTS `Users` (`id` INTEGER NOT NULL auto_increment , `name` VARCHAR(255), `createdAt` DATETIME NOT NULL, `updatedAt` DATETIME NOT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE utf8mb4_general_ci;',
parameters: undefined
},
sql: 'CREATE TABLE IF NOT EXISTS `Users` (`id` INTEGER NOT NULL auto_increment , `name` VARCHAR(255), `createdAt` DATETIME NOT NULL, `updatedAt` DATETIME NOT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE utf8mb4_general_ci;',
parameters: undefined
} |
|
I would like to have a go on this. |
|
Is this issue still open? I see a lot of commits referencing it. |
|
Any news on this? |
|
Is this still open? |

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.

sequelize/lib/model.js
Line 1271 in 8a1429d
If I create any model with
charset: 'utf8mb4', collate: 'utf8mb4_general_ci'sequelize translates it to this for mysql
CREATE TABLE IF NOT EXISTStablename... ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE utf8mb4_general_ci;On stepping through the code, it seems that the issue is here where we don't use the model's charset but the default charset.