• Home
  • Cloud VPS
    • Hong Kong VPS
    • US VPS
  • Dedicated Servers
    • Hong Kong Servers
    • US Servers
    • Singapore Servers
    • Japan Servers
  • Company
    • Contact Us
    • Blog
logo logo
  • Home
  • Cloud VPS
    • Hong Kong VPS
    • US VPS
  • Dedicated Servers
    • Hong Kong Servers
    • US Servers
    • Singapore Servers
    • Japan Servers
  • Company
    • Contact Us
    • Blog
ENEN
  • 简体简体
  • 繁體繁體
Client Area

How to Fix MySQL Error 1072 – SQLSTATE: 42000 (ER_KEY_COLUMN_DOES_NOT_EXITS) Key column ‘%s’ doesn’t exist in table

December 20, 2023

How to Fix MySQL Error 1072 – SQLSTATE: 42000 (ER_KEY_COLUMN_DOES_NOT_EXITS) Key column ‘%s’ doesn’t exist in table

MySQL is a popular open-source relational database management system used by many websites and applications. However, like any software, it can encounter errors that can disrupt its normal operation. One such error is the MySQL Error 1072 – SQLSTATE: 42000 (ER_KEY_COLUMN_DOES_NOT_EXITS) which indicates that a key column specified in a foreign key constraint does not exist in the referenced table. In this article, we will explore the causes of this error and provide solutions to fix it.

Causes of MySQL Error 1072

There are several reasons why you might encounter the MySQL Error 1072:

  • Typo or misspelled column name: Check if the column name specified in the foreign key constraint matches the actual column name in the referenced table. A simple typo or misspelling can cause this error.
  • Missing column: Ensure that the column specified in the foreign key constraint exists in the referenced table. If the column is missing, you need to add it to the table.
  • Table order: If you are creating multiple tables with foreign key constraints, make sure that the referenced table is created before the table with the foreign key constraint. Otherwise, MySQL will not find the referenced column and throw the error.

How to Fix MySQL Error 1072

Now that we understand the possible causes of the MySQL Error 1072, let’s explore the solutions to fix it:

1. Check for typos or misspelled column names

Review the foreign key constraint and verify that the column name specified matches the actual column name in the referenced table. Pay attention to any typos or misspellings. Correcting the column name should resolve the error.

2. Add the missing column

If the error message indicates that the key column doesn’t exist, you need to add the missing column to the referenced table. Use the ALTER TABLE statement to add the column with the appropriate data type and constraints.

ALTER TABLE referenced_table
ADD COLUMN column_name data_type constraints;

Replace referenced_table with the name of the referenced table and column_name with the name of the missing column. Specify the appropriate data_type and any necessary constraints.

3. Adjust the table creation order

If you are creating multiple tables with foreign key constraints, ensure that the referenced table is created before the table with the foreign key constraint. This ensures that the referenced column exists when the foreign key constraint is applied.

Summary

MySQL Error 1072 – SQLSTATE: 42000 (ER_KEY_COLUMN_DOES_NOT_EXITS) occurs when a key column specified in a foreign key constraint does not exist in the referenced table. This error can be caused by typos, missing columns, or incorrect table creation order. To fix this error, check for typos, add the missing column, or adjust the table creation order. If you need assistance with MySQL hosting and management, consider Server.HK for reliable and high-performance VPS hosting solutions.

Recent Posts

  • Hong Kong VPS Security Checklist: 10 Steps to Harden Your Server in 2026
  • NVMe SSD vs SATA SSD for VPS Hosting: Does Storage Type Really Matter?
  • Hong Kong VPS Docker Setup: Run Containers with Full Root Access
  • How to Set Up a Game Server on Hong Kong VPS: Low-Latency Gaming for Asia
  • How to Deploy a Node.js Application on Hong Kong VPS: Complete Guide

Recent Comments

  1. ivermectina tabletas on Top 5 Use Cases for a Hong Kong Dedicated Server in 2026
  2. hello world on Top 5 Use Cases for a Hong Kong Dedicated Server in 2026

Knowledge Base

Access detailed guides, tutorials, and resources.

Live Chat

Get instant help 24/7 from our support team.

Send Ticket

Our team typically responds within 10 minutes.

logo
Alipay Cc-paypal Cc-stripe Cc-visa Cc-mastercard Bitcoin
Cloud VPS
  • Hong Kong VPS
  • US VPS
Dedicated Servers
  • Hong Kong Servers
  • US Servers
  • Singapore Servers
  • Japan Servers
More
  • Contact Us
  • Blog
  • Legal
© 2026 Server.HK | Hosting Limited, Hong Kong | Company Registration No. 77008912
Telegram
Telegram @ServerHKBot