I'm trying to save emojis in my database, but I get always this error:
Error: ER_TRUNCATED_WRONG_VALUE_FOR_FIELD: Incorrect string value: '\xF0\x9F\x98\x9D' for column `myproject`.`cards`.`description` at row 1
I have tried to create the table this way:
CREATE TABLE cards (
id INT UNSIGNED PRIMARY KEY AUTO_INCREMENT,
date VARCHAR(10) NOT NULL,
time VARCHAR(8) NOT NULL,
place VARCHAR(200) NOT NULL,
instagram VARCHAR(200) NOT NULL,
description VARCHAR(3000) NOT NULL,
comments INT NOT NULL,
publication_date VARCHAR(20) NOT NULL
)ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
But it doesn't work.
My backend is made with node, and I insert the record into database this way:
CardCtrl.createCard = async (req, res) => {
logger.info(`Connecting to database...`, {
__filename
});
try {
var newCard = req.body;
newCard.comments = 0;
newCard.publicationDate = moment().format("DD-MM-YYYY HH:mm:ss");
console.log(newCard);
let query = `INSERT INTO Cards(date, time, place, instagram, description, comments, publication_date) VALUES("${newCard.date}", "${newCard.time}", "${newCard.place}", "${newCard.instagram}", "${newCard.description}", "${newCard.comments}", "${newCard.publicationDate}")`;
logger.info(`Creating card... Executing query: "${query}"`, {
__filename
});
bbdd.query(query, function (error, results, fields) {
if (error) {
logger.error(`Card does not created. ${error}`, {
__filename
});
res.status(400).json({
status: "KO",
message: "Card does not created"
});
return;
}
logger.info(`Card created`, {
__filename
});
res.status(200).json({
status: "OK",
message: "Card created"
});
});
} catch (error) {
logger.error(`An error has ocurred connecting to database: ${error}`, {
__filename
});
}
};
It's my first time working with emojis in database and I don't know how I should do this.
How can I solve this problem?