mysql - Foreign key constraint not being implemented -


i trying create foreign key between following 2 tables:

student:

id (pk, not null, unique, ai)

student_number (not null, unique)

... (other columns no constrains)

and

project:

id (pk, not null, unique, ai)

student_number(not null)

... (other columns no constrains)

the syntax using :

alter table project  add constraint fk_project_student foreign key (student_number)  references student (student_number) on delete cascade on update cascade; 

however following:

error 1452 (23000): cannot add or update child row: foreign key constraint fails

in case ask, there no team projects, simple 1 -to - many relationship.

you have records not meet foreign key constraint. find them using

select project.student_id project  left join student on project.student_number = student.student_number student.student_number null 

Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -