Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialKareem Jeiroudi
14,984 PointsAnyone had the problem that it kept adding the values 500 and -10, even after setting `PRAGMA FOREIGN_KEYS = on;`
There's my script, and whenever I'd run, it'd insert the last two rows, although it's not supposed to.
-- enter a query
PRAGMA FOREIGN_KEYS = ON;
DROP TABLE IF EXISTS TICKETS;
CREATE TABLE IF NOT EXISTS TICKETS (
ID INTEGER PRIMARY KEY AUTOINCREMENT,
CONCERT_ID SMALLINT REFERENCES CONCERTS(ID),
TICKET_HOLDER_ID INTEGER REFERENCES TICKET_HOLDERS(ID)
);
INSERT INTO TICKETS VALUES (NULL, 1, 3);
INSERT INTO TICKETS VALUES (NULL, 8, 2);
INSERT INTO TICKETS VALUES (NULL, 5, 5000);
INSERT INTO TICKETS VALUES (NULL, -10, 4);
SELECT * FROM TICKETS;
4 Answers
Sam Harris
4,883 PointsI had same Error: foreign key mismatch - "TICKETS" referencing "CONCERTS" issue.
For me the issue was that the ID for CONCERTS was not a PRIMARY KEY. If you go to CONCERTS table you should see PK at ID column, if not then the ID is not a PRIMARY KEY.
I fixed it by just DROPPING CONCERTS table and recreating it with the ID as SMALLINT PRIMARY KEY
rh16
3,781 PointsI am having a similar problem, but I skipped inserting the invalid values and went straight to the correct values. I get the same foreign key mismatch error. I don't see anything about the answer when I search the knowledge database. Can someone please help? I am stuck. Thank you.
Steven Parker
231,269 PointsIt is possible that those values exist in the other tables?
Kareem Jeiroudi
14,984 PointsYou mean that 5000 and -10 indeed exist in the TICKETS table?
Steven Parker
231,269 PointsWell, -10 in CONCERTS, and 5000 in TICKET_HOLDERS.
When I run this script, I get:
Error: foreign key mismatch - "TICKETS" referencing "CONCERTS"
But then the default CONCERTS table in the playground doesn't have a primary key. Try identifying the key column or rebuilding the table to have a key.
Mohammad Bazarbay
1,967 PointsSteven, I am having the same error as well. If anyone knows the answer, please let me know. Thanks
Alejandra Estefanía Aguilera Ávila
6,865 PointsAlejandra Estefanía Aguilera Ávila
6,865 PointsThat worked perfectly, thanks!