I'm doing a table creation in SQL and at the time of execution, I get an error "Foreign Key constraint is incorrectly formed"

0
CREATE TABLE doctor_schedule (
 doctor_id int(11) NOT NULL,
 attention_time_slot_id int(11) NOT NULL,
 available tinyint(1) NOT NULL DEFAULT '1',
 date date NOT NULL,
 PRIMARY KEY (doctor_id,attention_time_slot_id,date),
 FOREIGN KEY (doctor_id) REFERENCES doctor (id),
 FOREIGN KEY (attention_time_slot_id) REFERENCES attention_time_slot (id)
)
    
asked by MISAEL ALEXANDER RINCON RODRIG 19.05.2018 в 23:59
source

1 answer

0

I think it should be like this:

CREATE TABLE doctor_schedule (
 doctor_id int(11) NOT NULL,
 attention_time_slot_id int(11) NOT NULL,
 available tinyint(1) NOT NULL DEFAULT '1',
 date date NOT NULL,
 CONSTRAINT pk_doc_schedule PRIMARY KEY (doctor_id,attention_time_slot_id,date),
 CONSTRAINT fk_ds_doctor FOREIGN KEY (doctor_id) REFERENCES doctor (id),
 CONSTRAINT fk_ds_attention FOREIGN KEY (attention_time_slot_id) REFERENCES attention_time_slot (id)
)

Keep in mind that the types of foreign keys must be of the same type and same name.

    
answered by 20.05.2018 в 06:00