Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Development Tools

Database Foundations: Keys and Auto-Incrementing Values challenge

Q: Alter the "t_movies" table to add a foreign key called "fk_genre_id" and constrain it to reference the "t_genres" "pk_id".

So my answer so far is: alter table t_movies add coumn fk_genre_id integer add contraint foreign key (pk_id) reference t_genres(pk_id)

and the error its giving me is: Bummer! You're missing the 'fk_genre_id' column. I cant seem to understand where Im going wrong?

5 Answers

Try dropping the column keyword (it is optional) and/or the constraint keyword (optional when followed by "foreign key"). Also make sure you've spelled everything correctly. One character wrong would break everything.

  1. You need a comma to separate each add statement

  2. "add constraint" not "add contraint"

  3. you want to set the foreign key as fk_genre_id, not pk_id

  4. "references" not "reference"

Think that covers it.

EDIT: "Add column" with an l obviously, still gives same error

So Ive got: alter table t_movies add column fk_genre_id integer, add constraint foreign key (fk_genre_id) references t_genres(pk_id) But im still getting the missing the fk_genre_id error. am I missing anything else?

dropped the column and constraint keyword and it was correct. Thanks for your help