debugsqlMinor
"Error creating foreign key (check data types)…" but they do match…
Viewed 0 times
errorcreatingbutforeignmatchtypescheckdatatheykey
Problem
I'm getting the following error trying to create a constraint:
Problem is… those column data types do match.
The target is an
The source, in the same table, is an
Now, of course the target is
Is this really the problem? Why? How do I solve it, then? I don't want to be forced to insert a value there even when I don't need one, neither I want to enable
What else could be the problem?
Error creating foreign key (check data types)Problem is… those column data types do match.
The target is an
int(10) unsigned NOT NULL and is the PRIMARY column.The source, in the same table, is an
int(10) unsigned DEFAULT NULL, and the constraint I'm trying to create is a simple ON DELETE RESTRICT, ON UPDATE CASCADE.Now, of course the target is
NOT NULL and the source is NULL, but that's entirely intentional and what I need, and I can't see how could this be a problem. I could understand if it was the other way around…Is this really the problem? Why? How do I solve it, then? I don't want to be forced to insert a value there even when I don't need one, neither I want to enable
NULL on the PRIMARY column, which doesn't make much sense.What else could be the problem?
Solution
It was a bug with phpmyadmin.
When you create a new constraint you usually are allowed to leave its name field blank, and it fills it for you.
This time, for some still unknown reason, this didn't work and gave this unrelated error.
Filling the name field did the trick, and allowed me to create the constraint.
When you create a new constraint you usually are allowed to leave its name field blank, and it fills it for you.
This time, for some still unknown reason, this didn't work and gave this unrelated error.
Filling the name field did the trick, and allowed me to create the constraint.
Context
StackExchange Database Administrators Q#149516, answer score: 5
Revisions (0)
No revisions yet.