执行MySQL插入语句遇Error 1054错误,疑因数据类型问题求助
The immediate cause of your error is **incorrect use of backticks () for string values** in your INSERT statement. In MySQL, backticks are reserved for escaping column or table names—not for literal data. When you wrapped your userIDandreferenceName` values in backticks, MySQL interpreted them as column names instead of the string values you intended to insert, hence the "unknown column" message.
Step 1: Correct the Quote Usage
Replace the backticks around your values with single quotes ('). Here's the corrected INSERT statement:
INSERT INTO `new_table` (`userID`, `referenceName`, `id`) VALUES ('213526487623121521', '@RandomUser#5524', 1);
Step 2: Fix the id Primary Key Issue
Your table defines id as INT NOT NULL PRIMARY KEY, which means you must provide a value for it in every insert (unless you configure it to auto-increment). If you don't want to manually specify id each time, modify your table to make id auto-incrementing:
ALTER TABLE `new_table` MODIFY COLUMN `id` INT NOT NULL AUTO_INCREMENT;
With this change, you can omit id from your INSERT statement entirely:
INSERT INTO `new_table` (`userID`, `referenceName`) VALUES ('213526487623121521', '@RandomUser#5524');
Quick Recap
- Use single quotes (') for string literals in MySQL.
- Backticks (`) should only be used for column/table names that have special characters or are reserved keywords.
- Your
userIDvalue (213526487623121521) fits within thevarchar(20)limit, so data type mismatch isn't the issue here—though it's good you checked that angle!
内容的提问来源于stack exchange,提问作者CTLYST

