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 trial

Databases

Challenge 3 of 3: FOREIGN KEY Constraint.

Challenge 3 of 3: 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.

CREATE TABLE MEMBERS (ID PRIMARY KEY, FIRST_NAME, LAST_NAME, FOREIGN KEY(FAVORITE_ROCK_ID) REFERENCES ROCKS(ID));

6 Answers

Dale Severude
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Dale Severude
Full Stack JavaScript Techdegree Graduate 71,350 Points

You don't need the FOREIGN KEY on FAVORITE_ROCK_ID. Remove that and you are good.

CREATE TABLE MEMBERS (ID PRIMARY KEY, FIRST_NAME, LAST_NAME, FAVORITE_ROCK_ID REFERENCES ROCKS(ID));
Boban Talevski
Boban Talevski
24,793 Points

John, your code wouldn't work because the Foreign Key syntax isn't correct, at least according to SQL playground.

This should technically work, but it seems this challenge is buggy as the first one. I tried all lower case which was mostly the trick for the first one, didn't work. This is a version with keywords uppercase, everything else lower case, still doesn't work.

CREATE TABLE members (
    id PRIMARY KEY, 
    first_name, 
    last_name, 
    favorite_rock_id REFERENCES rocks(id)
);

The error message is this in all cases so far:

Bummer! Make sure you're creating all 4 columns: id, first_name, last_name, and favorite_rock_id.

And yeah, I copy pasted the names from the message for my column names :).

EDIT: The above code just passed after restarting the challenge and going through the tasks 1 and 2 again. So I guess they fixed it now, or it simply just started working.

They want you to add the keyword integer, work that in where it is appropriate

Kate Kuchinski
Kate Kuchinski
1,267 Points

DROP TABLE MEMBERS; ( id PRIMARY KEY, first_name, last_name, favorite_rock_id REFERENCES rocks(id) );

Boban Talevski
Boban Talevski
24,793 Points

Yeah I was referring to John's code, not yours...you posted an answer while I was writing my own, which I didn't see, so it looked like I was referring to your code, sorry :).

Thanks Dale. But I passed that part of the challenge. I am stuck on challenge 3.