System.Data.InvalidConstraintException: Parent Columns and Child Columns don’t have type-matching columns

If you encounter the error System.Data.InvalidConstraintException: Parent Columns and Child Columns don’t have type-matching columns, then the columns you’re trying to link do not have the same data type. In my case, I was trying to set a relationship between an “articles” table with a “categories” table. The “articles” table has a cat_id field as a foreign key and the “categories” table had its cat_id field as the primary key.

However the cat_id column in the “categories” table was defined as a tinyint(4) while the cat_id in “articles” was an int(11) data type. I changed cat_id in “articles” to tinyint(4) and the problem disappeared.

comments powered by Disqus