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.

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.