I am somewhat new to the database design and I have the following doubt: I have created a bd called "newdb" in which I create two tables (student and subject) with the following columns:
Student table
Field Type Null Key Default Extra
codigo_alumno int(11) NO PRI NULL auto_increment
nombre text NO NULL
materia_inscripto int(11) NO UNI NULL
Table subject
Field Type Null Key Default Extra
codigo_asignatura int(11) NO PRI NULL auto_increment
nombre_asignatura text NO NULL
numero int(11) NO MUL NULL
I would like to be able to add an FK that would allow me to relate the column 'asignatura_inscripto' of the 'student' table with the column 'number' of the subject table. The fact is that working with MySQL (InnoDB engine) does not allow it:
ALTER TABLE
alumno
ADD FOREIGN KEY (materia_inscripto
) REFERENCESasignatura
(numero
) ON DELETE SET NULL ON UPDATE CASCADE; MySQL has said: Documentation1215 - Unknown error 1215
Even rarer (at least, with my ignorance of the subject) is that if you allow me if I do not modify the "ON UPDATE" and "ON DELETE":
Your query was successfully executed. ALTER TABLE
alumno
ADD FOREIGN KEY (materia_inscripto
) REFERENCESasignatura
(numero
) ON DELETE RESTRICT ON UPDATE RESTRICT;
I already appreciate all the help you can give me. I have consulted several pages within the site and I do not think any frames with the same doubt that I have (several were solved by applying the same type of collation to the tables, others with the same type of data [in my case, everything is the same: all to utf8 and the related fields are unsigned integers]).
Note
If I forgot to specify any more data that is considered relevant, I am careful to be able to explain it later :). Greetings.