Quick Answer

Invalid string data for column encoding

Understanding the Issue

This error occurs when trying to insert characters that aren't supported by the column's character set (e.g., emojis in latin1 encoding).

The Problem

This code demonstrates the issue:

Sql Error
-- Problem: Unsupported characters
INSERT INTO products (name) VALUES ('Caf� au Lait'); -- If charset is latin1

The Solution

Here's the corrected code:

Sql Fixed
-- Solution 1: Change column encoding
ALTER TABLE products MODIFY name VARCHAR(100) CHARACTER SET utf8mb4;

-- Solution 2: Set database/client charset
SET NAMES utf8mb4; -- At connection start

-- Solution 3: Encode special characters
INSERT INTO products (name) VALUES ('Café au Lait'); -- HTML entities

-- Solution 4: Use parameterized queries
-- Let driver handle encoding

Key Takeaways

Ensure database and client character sets support your data.