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

My answer doesn't pass. I've copied the command into mysql workbench and the table is created with no issues;

The command works fine in Mysql Workbench; i'm not sure if this is a bug or i need to format my script a little bit differently.

CREATE TABLE t_genres (pk_id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY, uk_name VARCHAR(45) NOT NULL);

Error Message: There's something wrong with the definition of your column named 'uk_name'. on some occasions if i make other adjustments i would also get an error that says pk_id does not have a primary key

2 Answers

Julian Aramburu
Julian Aramburu
11,367 Points

I think you have to set your uk_name column to "UNIQUE KEY" as it says "...and a unique column called "uk_name" that can't be null...." so after your "NOT NULL" you need to add "UNIQUE KEY" also I think you could only add UNIQUE KEY as UNIQUE KEYS cant be null.

Hope it helps :D!

Cheers and Keep Coding!

Thanks Julian! it worked in the code challenge, do you have any idea why it worked in MYSQL Workbench and not on Treehouse?

Julian Aramburu
Julian Aramburu
11,367 Points

it could be because you are asked to create an UNIQUE column... and you weren't creating one... It's going to work in your workbench because you are not forced to create anything specific

Julian Aramburu
Julian Aramburu
11,367 Points

Hi mate! it would be helpful if you paste your code in order to check it!

Cheers!

CREATE TABLE t_genres (pk_id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY, uk_name VARCHAR(45) NOT NULL);

Error Message: There's something wrong with the definition of your column named 'uk_name'. on some occasions if i make other adjustments i would also get an error that says pk_id does not have a primary key