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

Leigh Maher
Leigh Maher
21,830 Points

Can't get it to create genre_id in the movies table?

I'm trying to add the genre_id to the movies table by use this line of sql:

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

But I get this error: Error Code: 1005. Can't create table 'treehouse_movie_db.#sql-1c6_24' (errno: 150) 0.114 sec

It's the same line (I think) that Andrew puts in but it won't work for me?

Thanks.

1 Answer

You may want to check the DB Engine being used on the "genres" table. In doing some investigation in the Table Inspector after experiencing a similar issue, I found that the engines between my "movies" and "genres" tables were different, thus, throwing an incompatibility error when trying to connect the keys. When I converted the "genres" engine to InnoDB, the alter statement worked. Hope this helps!

Leigh Maher
Leigh Maher
21,830 Points

Hi Valerie, I did resolve this issue, but I can't remember how. I'm pretty sure it had something do with the engine, though. So, I think you're correct here. Thanks.