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 Joining Tables and Aliasing

Forgot to add genres_id column

Hello,

I've been attempting to create the Database on mySQL workbench as I have been watching through the videos.

It seems somewhere I have possibly forgotten to add the genres_id as it is not currently shown in my 'genres' table.

This is the error message being returned:

"10:00:56 SELECT * FROM movies JOIN genres ON movies.genre_id = genres_id LIMIT 0, 1000 Error Code: 1054. Unknown column 'genres_id' in 'on clause' 0.000 sec"

Could someone please advise what statement I would require to solve this error being returned?

I have attempted adding it myself:

3 32 14:15:04 ALTER TABLE genres ADD COLUMN genres_id INTEGER 0 row(s) affected Records: 0 Duplicates: 0 Warnings: 0 0.078 sec

I would guess that it is completely wrong as when I use the statement from the video:

SELECT * FROM movies JOIN genres ON movies.genre_id = genres_id;

There are absolutely no values returned across the 7 columns (id, title, year, genre_id, id, name, genres_id)

It would be much appreciated if someone could help me out. Thank you in advance.

1 Answer

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hi Michael,

Try ->

ALTER TABLE movies ADD COLUMN genre_id INTEGER NULL, ADD CONSTRAINT FOREIGN KEY (genre_id) REFERENCES genres(id);

Hope that works. :)