I'm trying to create an Associative Entity (N:N) in SQLite like this:

[ Pet ---< VaccinePet >--- Vaccine ]

And, I have the follow code of my associative entity:

        vp_date TEXT NOT NULL,
        vp_is_applied INTEGER DEFAULT 0,
        fk_pet INTEGER,
        fk_vaccine INTEGER,
        FOREIGN KEY (fk_pet) REFERENCES pet (pet_id),
        FOREIGN KEY (fk_vaccine) REFERENCES vaccine (vaccine_id),
        PRIMARY KEY (fk_pet, fk_vaccine) 

BUT, I'm getting an error:

foreign key mismatch - "VACCINEPET" referencing "vaccine": INSERT INTO VACCINEPET (vp_date, vp_is_applied, fk_pet, fk_vaccine) VALUES ('23/05/2018', 0, 1, 1);

When I try to use the INSERT command:

INSERT INTO VACINAPET (vp_data, vp_is_aplicada, fk_pet, fk_vacina) VALUES ('23/05/2018', 0, 1, 1);

What could be wrong? I'm not so good in database... :(

MASTER DETAIL: I have data in Pet table and Vaccine table, they are not empty

  • Your insert statement seems to be in Spanish or similar, so I assume that's not the actual statement for the table as given here? Anyway, do you have records in the Pet and Vaccine tables each with primary key values of 1? What are the data types of these primary keys? And are they perhaps defined as NOT NULL? It would probably help to see the CREATE statements for both these tables.
    – dbdemon
    Jan 18, 2018 at 8:42

1 Answer 1


The error message "foreign key mismatch" does not indicate a constraint violation, but that your database schema is wrong.

Assuming that the vaccine table and the vaccine_id column actually exist, the most likely reason is that the required index is missing, i.e., that vaccine_id is not the primary key (or at least unique).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.