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

Development Tools Database Foundations Joining Relational Data Between Tables in SQL Keys and Auto-Incrementing Values

Marcia Haledjian
Marcia Haledjian
7,562 Points

Answer for challenge task 3

Stuck on task 3, my answer is:

alter table t_movies add column fk_genre_id integer null, add constraint foreign key(fk_genre_id) references fk_genre_id(t_genres, pk_id)

4 Answers

Andrew Showalter
Andrew Showalter
14,028 Points

As I said before, you only needed to modify the references statement. Here is a working query. Please see the end in the REFERENCES where you had a slight error in your statement.

ALTER TABLE t_movies ADD COLUMN fk_genre_id INTEGER NULL, ADD CONSTRAINT FOREIGN KEY (fk_genre_id) REFERENCES t_genres(pk_id);

Hope that helps!

Andrew Showalter
Andrew Showalter
14,028 Points

I believe your issue is at the end of the statement after "REFERENCES". You only need to reference the tablename(column). So, it probably REFERENCES genres(id)

Marcia Haledjian
Marcia Haledjian
7,562 Points

OK, this is the challenge: Alter the "t_movies" table to add a foreign key called "fk_genre_id" and constrain it to reference the "t_genres" "pk_id". I try almost everything, what i did not try because I can not see, please help

Andrew Showalter
Andrew Showalter
14,028 Points

Could you select the best answer and label this question as answered please...