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 trialTroy Erby
6,332 PointsTrouble inserting Primary Key
The challenge question reads, "Now recreate the MEMBERS table with the new FAVORITE_ROCK_ID column, and make sure it has a foreign key constraint to the ID column of the ROCKS table. The columns should now be: ID, FIRST_NAME, LAST_NAME, and FAVORITE_ROCK_ID.
I wrote the code: CREATE TABLE MEMBERS (ID PRIMARY KEY, FIRST_NAME, LAST_NAME, FAVORITE_ROCK_ID REFERENCES ROCKS(ID))
I keep getting the error message "Make sure you're id only allows unique values. Hint: ID PRIMARY KEY". I thought my syntax for handling that was correct, to simply add "PRIMARY KEY" after the ID. I tried to fix it by adding "PRAGMA FOREIGN KEYS= ON;" in front of my code but received the error message that my code must begin with a "CREATE" statement. What am I missing?
Brendan Whiting
Front End Web Development Techdegree Graduate 84,738 PointsCan you post the full SQL that youβre using?
2 Answers
Steven Parker
231,236 PointsI pasted your line directly into the challenge and it passed! Try again?
CREATE TABLE MEMBERS (ID PRIMARY KEY, FIRST_NAME, LAST_NAME, FAVORITE_ROCK_ID REFERENCES ROCKS(ID))
Troy Erby
6,332 PointsWeird. I copied and pasted this exact statement again and continued to get the same error message. Thanks to you I trusted that the code must work so I logged out, logged back in and redid the 1st 2 steps of the challenge and THEN copied and pasted and...Voila. Thanks for the feedback otherwise I'd still be banging my head against the wall looking for a phantom error.
Troy Erby
6,332 PointsSorry, I thought the code was automatically copied into the message. I've added it now.
Steven Parker
231,236 PointsSteven Parker
231,236 PointsIt would help if you show the complete SQL code you are entering.