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 trialBrandi Bizek
1,074 PointsSQL - Keys and Auto-Incrementing Values, challenge task 3
I can't seem to get this one... I'm asked to: Alter the "t_movies" table to add a foreign key called "fk_genre_id" and constrain it to reference the "t_genres" "pk_id".
Here's my attempt:
ALTER TABLE t_movies ADD COLUMN fk_genre_id INTEGER NULL ADD CONTRAINT FOREIGN KEY (fk_genre_id) REFERENCES t_genres(pk_id);
Here's what I get back: Bummer! You're missing the 'fk_genre_id' column.
What am I doing wrong? Didn't I add the column with the "ADD COLUMN fk_genre_id INTEGER NULL" key words? I'm still doing something wrong, but I can't figure it out. The SQL syntax reference on the mySQL site isn't helping.
Help!
Thanks! Brandi
8 Answers
Alex Sollman
5,353 PointsHello,
I was just having the EXACT problem you were, and found out that we were both missing a comma.
ALTER TABLE t_movies ADD COLUMN fk_genre_id INTEGER NULL, ADD CONSTRAINT FOREIGN KEY (fk_genre_id) REFERENCES t_genres(pk_id);
I passed with this, hope it helps!
Mohammed Hossen
5,591 PointsALTER TABLE t_movies ADD COLUMN fk_genre_id INTEGER, ADD CONSTRAINT FOREIGN KEY (fk_genre_id) REFERENCES t_genres(pk_id);
The code will work if you separate the two words "INTEGER, ADD" with comma. The missing comma is keep throwing an error saying 'fk_genre_id' column is missing.
Ram Ada
360 PointsDid you mean CONSTRAINT instead of CONTRAINT?
Robert Hustwick
13,058 PointsMan! It took forever to figure out that I was typing it in wrong! Thanks.
shahardekel
20,306 PointsI just had the exact same problem (even used the same SQL as Brandi Bizek did. Adding the comma did the job. thanks!
Theodore Karropoulos
22,149 PointsIf anyone still trying to find a solution add the following code.
ALTER TABLE t_movies ADD fk_genre_id INTEGER, ADD CONSTRAINT FOREIGN KEY(fk_genre_id) REFERENCES t_genres(pk_id)
Sean Flanagan
33,235 PointsThank you for this thread. It's just proven to be a big help in cracking this challenge! :-)
Brandi Bizek
1,074 PointsOops! Yes, that's what I meant. I've tried it so many times... this, unfortunately, wasn't the problem. I've fixed the spelling typo and still get the same "bummer" response: ALTER TABLE t_movies ADD COLUMN fk_genre_id INTEGER ADD CONSTRAINT FOREIGN KEY (fk_genre_id) REFERENCES t_genres(pk_id);
Ideas?
Anca Dragan
8,750 PointsHei! I found what was missing from your code... ALTER TABLE t_movies ADD COLUMN fk_genre_id INTEGER ADD CONSTRAINT FOREIGN KEY (fk_genre_id) REFERENCES t_genres(pk_id); That is your code.. and you are missing a comma between "INTEGER" and the "ADD CONSTRAINT" :D
John Locke
15,479 PointsJohn Locke
15,479 PointsI got stuck on the syntax, too. Thanks Alex!
Joshua Perry
2,962 PointsJoshua Perry
2,962 PointsSame here. Thanks Alex!