Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Model options.charset is overwritten by default options #12273

Open
rohitsud opened this issue May 18, 2020 · 10 comments
Open

Model options.charset is overwritten by default options #12273

rohitsud opened this issue May 18, 2020 · 10 comments
Labels
good first issue type: bug

Comments

@rohitsud
Copy link

@rohitsud rohitsud commented May 18, 2020

options = { ...this.options, ...options };

If I create any model with
charset: 'utf8mb4', collate: 'utf8mb4_general_ci'

sequelize translates it to this for mysql

CREATE TABLE IF NOT EXISTS tablename ... 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.

@sushantdhiman

This comment has been minimized.

@rohitsud

This comment has been minimized.

@rohitsud

This comment has been minimized.

@sushantdhiman
Copy link
Contributor

@sushantdhiman sushantdhiman commented May 20, 2020

I can confirm this bug on master. I have noticed you are using 4.44.3, if this bug is fixed, it wont be released for v4/v3 branches as they are deprecated.

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
}

@sushantdhiman sushantdhiman reopened this May 20, 2020
@sushantdhiman sushantdhiman added good first issue type: bug labels May 20, 2020
JuarezLustosa added a commit to JuarezLustosa/sequelize that referenced this issue Jul 22, 2020
JuarezLustosa added a commit to JuarezLustosa/sequelize that referenced this issue Jul 22, 2020
JuarezLustosa added a commit to JuarezLustosa/sequelize that referenced this issue Jul 22, 2020
JuarezLustosa added a commit to JuarezLustosa/sequelize that referenced this issue Jul 22, 2020
JuarezLustosa added a commit to JuarezLustosa/sequelize that referenced this issue Jul 22, 2020
@mearns
Copy link

@mearns mearns commented Oct 1, 2020

Is this issue still open? I see a lot of commits referencing it.

@LouiZibdawi
Copy link

@LouiZibdawi LouiZibdawi commented Oct 16, 2020

Any news on this?

@Edu93Jer
Copy link

@Edu93Jer Edu93Jer commented Dec 4, 2020

Is this still open?

1 similar comment
@iengonline
Copy link

@iengonline iengonline commented May 21, 2021

Is this still open?

@github-actions
Copy link
Contributor

@github-actions github-actions bot commented Nov 2, 2021

This issue has been automatically marked as stale because it has been open for 7 days without activity. It will be closed if no further activity occurs. If this is still an issue, just leave a comment or remove the "stale" label. 🙂

@github-actions github-actions bot added the stale label Nov 2, 2021
@rohitsud
Copy link
Author

@rohitsud rohitsud commented Nov 2, 2021

Still an issue

@github-actions github-actions bot removed the stale label Nov 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue type: bug
Projects
None yet
Development

No branches or pull requests

6 participants