I'm trying to create a Associative Entity (N: N) in SQLite like this:
[Pet --- < VaccinePet> Vaccine]
And, here is my Associative Entity code
CREATE TABLE VACINAPET (
vp_data TEXT NOT NULL,
vp_is_aplicada INTEGER DEFAULT 0,
fk_pet INTEGER,
fk_vacina INTEGER,
FOREIGN KEY (fk_pet) REFERENCES pet (pet_id),
FOREIGN KEY (fk_vacina) REFERENCES vacina (vacina_id),
PRIMARY KEY (fk_pet, fk_vacina)
);
The code for my Pet entity:
CREATE TABLE PET (
pet_id INTEGER PRIMARY KEY AUTOINCREMENT,
pet_nome TEXT NOT NULL,
pet_genero INTEGER DEFAULT 0,
pet_foto_perfil TEXT,
pet_peso INTEGER DEFAULT 0,
pet_dt_nasc TEXT,
fk_tpanimal INTEGER,
fk_raca INTEGER,
FOREIGN KEY (fk_tpanimal) REFERENCES TIPOANIMAL (tpanimal_id),
FOREIGN KEY (fk_raca) REFERENCES RACA (raca_id)
);
And the code of my entity Vaccine:
CREATE TABLE VACINA (
vac_id INTEGER PRIMARY KEY AUTOINCREMENT,
vac_validade TEXT NOT NULL,
fk_tipo INTEGER,
FOREIGN KEY (fk_tipo) REFERENCES tipovacina (tpvac_id)
);
BUT, I get this error here:
foreign key mismatch - "VACINAPET" referencing "vaccine": INSERT INTO VACINAPET (vp_data, vp_is_applied, fk_pet, fk_vacina) VALUES ('23 / 05/2018 ', 0, 1, 1);
When I try to use the following INSERT command:
INSERT INTO VACINAPET (vp_data, vp_is_applied, fk_pet, fk_vacina) VALUES ('23 / 05/2018 ', 0, 1, 1);
What could be wrong?
NOTE: I have data in the Pet and Vaccine tables, they are not empty data