msgbartop
Of Linux, Programming, and Singaporean Ramblings
msgbarbottom

17 Dec 08 MySQL Error 1452

This is to help developers who encounter the error ERROR 1452 (23000) in MySQL resolve it.

There can be a few causes to this error. One of the reasons is the newline characters that terminate each line. There are differences between the Windows platform and the Linux-based platforms when terminating each line. Refer to this forum post for more information.

The other reason I found out personally is the existing data in the table. For example, suppose the field in the table was of type VARCHAR(20) and all rows have numeric strings in this field. Even if the field was modified to be an integer type, referencing this field to a numeric field in another table will not work because the data in the rows are character types. Therefore, before the foreign key constraint can be created, the data in the field has to be changed to integer types.

Reader's Comments

  1. |

    I want to say my particular experience with this error code. It happened to me when I tried to alter an InnoDB table, who had rows with data who had no longer reference, because the parent had been deleted. I only deleted those rows and I could alter the table. I hope this can help you.

  2. |

    Thanks Juan. Yes it does. More likely than not, such errors are associated with foreign key constraints. That’s something I’ve looked out for any time I see the error.

Leave a Comment