Error # 1452 when trying to relate two tables

0

I try to relate two tables (users and comments), the primary user key is idUsuario, and the foreign key of the comments table is userid.

  

I have also specified the two tables as InnoDB.

  

And in the next image the primary and foreign key of   the comments table.

  

By going to the Designer section and relating the primary key   UserID (from the users table) with the foreign key UserID (from the   comment table), the following error appears:

Does anyone know why this error appears and how it could be solved?

    
asked by Mario G. Lucas 02.10.2018 в 11:43
source

1 answer

1

When restrictions of any kind are established in one or more tables, the engine verifies that the new restrictions are met for each of the rows of the tables involved.   Surely you have records in your comments table with a UserID that does not exist in the Users table. If you clean the data in the tables or generate the corresponding User for each of the comments, this Problem should not arise.

    
answered by 02.10.2018 в 16:03