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

Databases

Difficulty with Code Challenge.

I am having severe difficulties with the Task Challenge 3 with Auto_Incrementing keys. I have struggled to get past this Challenge. Is there anyway to help me determine what is wrong with the following command?

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

Thanks in advance for your help.

Steven Parker
Steven Parker
231,140 Points

Could you provide a link to the challenge page? Or at least mention which course this is for.

2 Answers

Steven Parker
Steven Parker
231,140 Points
  • you do need a comma before "ADD CONSTRAINT ..."
  • the term "FOREIGN KEY" comes after "CONSTRAINT"
  • the term "REFERENCES" must be spelled with an "S"

So the revised query would be:

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

Steven,

Thanks for your help. Here is the link. I tried adding a comma without success.

Thanks again. Any insights are welcome. I am still struggling.

https://teamtreehouse.com/library/database-foundations/joining-relational-data-between-tables-in-sql/keys-and-autoincrementing-values-2

Regards,

Kirk

Steve,

Thank you very much. That worked great.

Regards,

Kirk