1054 ошибка mysql insert

I keep getting

Error Code: 1054
Unknown column ‘originalFieldName’ in ‘field list’

when trying to insert a new record to a table. This still happens even when I am not inserting any value to this problematic column ‘originalFieldName’. Renaming the field and ensuring I don’t have unprintable characters like suggested in solutions to this question does not help either.

I have since reduced my query to
INSERT INTO incoming(receiptDate)
VALUES(NOW());

and deleted some fields to remain with below table:
table description
but this error 1054 keeps popping up

Community's user avatar

asked Nov 3, 2016 at 15:19

ken macharia's user avatar

3

The error was caused by a trigger which was doing a comparison on ‘originalFieldName’. I had forgotten to specify it as new.originalFieldName to refer to the newly inserted value in that field and thus MySQL reported it as unknown column.

answered Nov 4, 2016 at 14:37

ken macharia's user avatar

ken machariaken macharia

711 gold badge1 silver badge7 bronze badges

Are you using mysql ? If you are using mysql then there could be a difference in back tick ( `someValue ` ) . Keep considering this point and see if it helps . If you are using other DB then please let me know . It seems some invisible characters has been introduced there . May be you have copied it from somewhere . Please let me know DB details and paste full code.

answered Nov 3, 2016 at 15:30

Manish Kumar's user avatar

7

MySQL error code 1054 happens if we forget to add single quotes while inserting a varchar value or due to any missing column.

Here at Ibmi Media, We have seen several request from our customers regarding MySQL issues and in particular the «MySQL error code 1054«.

In this context, we will discuss the causes of common MySQL errors like this and how to fix them.

What causes MySQL error code 1054?

From our experience in handling and finding solutions to MySQL problems, below are the common reasons why this error happens;
1. When there is an error in the CREATE_TABLE and UPDATE statements.
2. When there is a missing column in a Database table.
3.
When you do not use the correct quote when dealing with a Varchar
value. It is recommend to use single quotes when inserting a varchar
character.
4. When the name of a column does not align with what is being implemented in an UPDATE statement.

Ways to fix MySQL error code 1054

Our
Support Team found some ways to go about fixing this error and we will
share them below. You can follow the following steps to solve MySQL
issues;

1. It is important that when creating a table, ensure that you remove any inappropriate spacing or incorrect characters.
2. We ensure that the naming of the column follows the ASCII characters standard.
3. Always use single quotes when dealing with a string  and varchar characters.
4.
To do a proper fix, you should troubleshoot the database in a local
environment by exporting from the phpmyadmin it to your local machine
Localhost. Then edit the SQL file and look into the affected table to
see if single quotes was not used properly.

Afterwards, you can make an ALTER SQL query to add any missing column in the Table. To do this, use the query below;
ALTER TABLE <table_name> ADD <column_name> <datatype> AFTER <after_column>

[Do you need support in fixing MySQL errors? We can help you Today.]

Conclusion

In
summary, MySQL error code 1054 is as a result of a missing column, or when a
single quote is not used in the Create or Update statements. To fix
other Database errors, Consult our MySQL Experts Today.

I keep getting

Error Code: 1054
Unknown column ‘originalFieldName’ in ‘field list’

when trying to insert a new record to a table. This still happens even when I am not inserting any value to this problematic column ‘originalFieldName’. Renaming the field and ensuring I don’t have unprintable characters like suggested in solutions to this question does not help either.

I have since reduced my query to
INSERT INTO incoming(receiptDate)
VALUES(NOW());

and deleted some fields to remain with below table:
table description
but this error 1054 keeps popping up

Community's user avatar

asked Nov 3, 2016 at 15:19

ken macharia's user avatar

3

The error was caused by a trigger which was doing a comparison on ‘originalFieldName’. I had forgotten to specify it as new.originalFieldName to refer to the newly inserted value in that field and thus MySQL reported it as unknown column.

answered Nov 4, 2016 at 14:37

ken macharia's user avatar

ken machariaken macharia

711 gold badge1 silver badge7 bronze badges

Are you using mysql ? If you are using mysql then there could be a difference in back tick ( `someValue ` ) . Keep considering this point and see if it helps . If you are using other DB then please let me know . It seems some invisible characters has been introduced there . May be you have copied it from somewhere . Please let me know DB details and paste full code.

answered Nov 3, 2016 at 15:30

Manish Kumar's user avatar

7

When you execute a MySQL statement, you may sometimes encounter ERROR 1054 as shown below:

mysql> SELECT user_name FROM users;
ERROR 1054 (42S22): Unknown column 'user_name' in 'field list'

The ERROR 1054 in MySQL occurs because MySQL can’t find the column or field you specified in your statement.

This error can happen when you execute any valid MySQL statements like a SELECT, INSERT, UPDATE, or ALTER TABLE statement.

This tutorial will help you fix the error by adjusting your SQL statements.

Let’s start with the SELECT statement.

Fix ERROR 1054 on a SELECT statement

To fix the error in your SELECT statement, you need to make sure that the column(s) you specified in your SQL statement actually exists in your database table.

Because the error above says that user_name column is unknown, let’s check the users table and see if the column exists or not.

To help you check the table in question, you can use the DESCRIBE or EXPLAIN statement to show your table information.

The example below shows the output of EXPLAIN statement for the users table:

mysql> EXPLAIN users;
+--------------+-------------+------+-----+---------+-------+
| Field        | Type        | Null | Key | Default | Extra |
+--------------+-------------+------+-----+---------+-------+
| username     | varchar(25) | NO   |     |         |       |
| display_name | varchar(50) | NO   |     |         |       |
| age          | int         | YES  |     | NULL    |       |
| comments     | text        | YES  |     | NULL    |       |
+--------------+-------------+------+-----+---------+-------+

From the result above, you can see that the users table has no user_name field (column)

Instead, it has the username column without the underscore.

Knowing this, I can adjust my previous SQL query to fix the error:

SELECT username FROM users;

That should fix the error and your SQL query should show the result set.

Fix ERROR 1054 on an INSERT statement

When you specify column names in an INSERT statement, then the error can be triggered on an INSERT statement because of a wrong column name, just like in the SELECT statement.

First, you need to check that you have the right column names in your statement.

Once you are sure, the next step is to look at the VALUES() you specified in the statement.

For example, when I ran the following statement, I triggered the 1054 error:

mysql> INSERT INTO users(username, display_name) 
    ->   VALUES ("jackolantern", Jack);
ERROR 1054 (42S22): Unknown column 'Jack' in 'field list'

The column names above are correct, and the error itself comes from the last entry in the VALUES() function.

The display_name column is of VARCHAR type, so MySQL expects you to insert a VARCHAR value into the column.

But Jack is not a VARCHAR value because it’s not enclosed in a quotation mark. MySQL considers the value to be a column name.

To fix the error above, simply add a quotation mark around the value. You can use both single quotes or double quotes as shown below:

INSERT INTO users(username, display_name) 
  VALUES ("jackolantern", 'Jack');

Now the INSERT statement should run without any error.

Fix ERROR 1054 on an UPDATE statement

To fix the 1054 error caused by an UPDATE statement, you need to look into the SET and WHERE clauses of your statement and make sure that the column names are all correct.

You can look at the error message that MySQL gave you to identify where the error is happening.

For example, the following SQL statement:

UPDATE users
SET username = "jackfrost", display_name = "Jack Frost"
WHERE user_name = "jackolantern";

Produces the following error:

ERROR 1054 (42S22): Unknown column 'user_name' in 'where clause'

The error clearly points toward the user_name column in the WHERE clause, so you only need to change that.

If the error points toward the field_list as shown below:

ERROR 1054 (42S22): Unknown column 'displayname' in 'field list'

Then you need to check on the SET statement and make sure that:

  • You have the right column names
  • Any string type values are enclosed in a quotation mark

You can also check on the table name that you specified in the UPDATE statement and make sure that you’re operating on the right table.

Next, let’s look at how to fix the error on an ALTER TABLE statement

Fix ERROR 1054 on an ALTER TABLE statement

The error 1054 can also happen on an ALTER TABLE statement.

For example, the following statement tries to rename the displayname column to realname:

ALTER TABLE users 
  RENAME COLUMN displayname TO realname;

Because there’s no displayname column name in the table, MySQL will respond with the ERROR 1054 message.

Conclusion

In short, ERROR 1054 means that MySQL can’t find the column name that you specified in your SQL statements.

It doesn’t matter if you’re writing an INSERT, SELECT, or UPDATE statement.

There are only two things you need to check to fix the error:

  • Make sure you’ve specified the right column name in your statement
  • Make sure that any value of string type in your statement is surrounded by a quotation mark

You can check on your table structure using the DESCRIBE or EXPLAIN statement to help you match the column name and type with your statement.

And that’s how you fix the MySQL ERROR 1054 caused by your SQL statements.

I hope this tutorial has been useful for you 🙏

Normally MySQL Error 1054 occurs due to missing column, typos in varchar insertion, or many reasons. If you encounter such an error, you may need to put in endless hours to fix this error. In this tutorial, I am going to share some quick fix tips to save your time. So let’s get started.

Possible Reasons of MySQL Error 1054

  • Missing column in a table.
  • Single quotes missing while inserting varchar value.
  • Mismatch between CREATE_TABLE and UPDATE.

To fix MySQL 1054 Error, follow the steps mentioned below.

Step 1: Check the database

If you just migrated the database from different hosting or upload from local host, you may have some errors during database dump creation. Check the sql file on any editor.

Step 2: Update all the single quotes if any

Check the database to fix the single quotes around the string value.

Step 3: Remove Unnecessary Space

Remove all unnecessary spaces or strings from the database table.

Step 4: Alter table name to fix MySQL 1054 Error

You may need to alter the column name.

Moreover, this error may occurs due to some other reason as well.

Read More: How to fix MySQL 1064 Error.

Conclusion

In this article, I have explained how to fix MySQL error 1054 quickly. If you have any doubt, feel free to comment below. Also, you can join our elite Facebook group to get direct help from me. If you like this article, please share this article on your social media handle.

Rajesh Shivam is a seasoned professional with expertise in AWS and Linux System Administration. With over 10 years of freelancing experience, he brings a wealth of knowledge to the table. Rajesh has a strong passion for technology and stays connected with the latest happenings in the field. His dedication and expertise make him a trusted resource for all things tech-related.

Понравилась статья? Поделить с друзьями:
  • 105035 ошибка zoom как устранить
  • 1048833 ошибка шкода рапид
  • 10449 ошибка ауди
  • 1044 ошибка vag
  • 10434 ошибка ауди