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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Brandi Bizek](https://uploads.teamtreehouse.com/production/profile-photos/105242/micro_me.jpg)
Brandi 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](https://secure.gravatar.com/avatar/c4e2e74066ae5c3ff06d3b4ebe656a75?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
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](https://uploads.teamtreehouse.com/production/profile-photos/129836/micro_417812_10101865561671932_200780274_n.jpg)
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](https://secure.gravatar.com/avatar/ca814e1ee88d3a1244cd318ec09b6d9e?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Ram Ada
360 PointsDid you mean CONSTRAINT instead of CONTRAINT?
![Robert Hustwick](https://uploads.teamtreehouse.com/production/profile-photos/85727/micro_diploma.jpg)
Robert Hustwick
13,058 PointsMan! It took forever to figure out that I was typing it in wrong! Thanks.
![shahardekel](https://secure.gravatar.com/avatar/ec7f2ae7e9c95a668b1d2bb318ec28fb?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
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](https://secure.gravatar.com/avatar/cf754d135c2c4bb6763bb40c1c96dbef?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
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](https://uploads.teamtreehouse.com/production/profile-photos/881172/micro_Sean.jpg)
Sean Flanagan
33,235 PointsThank you for this thread. It's just proven to be a big help in cracking this challenge! :-)
![Brandi Bizek](https://uploads.teamtreehouse.com/production/profile-photos/105242/micro_me.jpg)
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](https://uploads.teamtreehouse.com/production/profile-photos/116093/micro_cougar_1_by_canisography-d5rrq24.jpg)
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!