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.

PHP

Charles Gray
Charles Gray
19,470 Points

Database help

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

ALTER TABLE t_movies ADD COLUMN fk_genres_id INTEGER NULL, CONSTRAINT FOREIGN KEY(fk_genre_id) REFERENCE t_genres(ph_id)

I think I've tried everything, even wrote instructions down and followed it, nothing seems to work

James Barnett
James Barnett
39,199 Points

To help us better help you we need to see the code you are using. For some tips on how to do that, check out the tips for asking questions video located in the right hand sidebar.

8 Answers

Charles Gray
Charles Gray
19,470 Points

OK i figured it out REFERENCE, needed to be REFERENCES with an 's'

use REFERENCES, instead of REFERENCE

Charles Gray
Charles Gray
19,470 Points

ALTER TABLE t_movies ADD COLUMN fk_genres_id INTEGER NULL, CONSTRAINT FOREIGN KEY(fk_genre_id) REFERENCE t_genres(ph_id)

try

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

typo issue

Charles Gray
Charles Gray
19,470 Points

That didn't work at all.

Vernon Watson
Vernon Watson
8,854 Points

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

YAYYY!

I am getting an error, "You're missing the 'fk_genre_id' column".

This is my code below:

ALTER TABLE t_movies ADD COLUMN fk_genre_id INTEGER, ADD CONSTRAINT FOREIGN KEY(fk_genre_id) REFERENCE t_genres(ph_id);

Any suggestions?

Kevin Fitzhenry
Kevin Fitzhenry
30,096 Points

I keep getting this error as well. Is there a bug in the challenge? Did it eventually pass for you?

Nevermind.