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

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.