In MySQL beginner, encountered this problem.
Existing two tables, student and class. The student table has the ID as the primary key, the name and the Classid,class table have the ID as the primary key, and the name is ready to set the ClassID as the foreign KEY constraint. The statements are as follows
ALTER TABLE student ADD constraint Fk_stu_classid foreign key (ClassID) references class (ID);
There is no error after checking the statement, but the error message is as follows;
Can ' t create table ' db_19. #sql -153c_4 ' (errno:150)
Depressed for a half day after the definition of the query foreign key, the requirement is the same type as the associated primary key, so the problem is resolved after the modification.
Another situation was found after the query
When this type of error occurs, start with three angles:
1. Make sure the primary table has a primary key.
2, ensure that the master-slave table data engine is InnoDB type.
3. Make sure that the key field type from the table is the same as the primary table .
So this is the wrong thing to happen.
This article is from the "Neruda" blog, make sure to keep this source http://neruda.blog.51cto.com/9652194/1583023
Problems encountered while adding foreign keys