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

Create a genres table called "t_genres" with an auto incrementing primary key called "pk_id" and a unique column called

Create a genres table called "t_genres" with an auto incrementing primary key called "pk_id" and a unique column called "uk_name" that can't be null. The "uk_name" is a varchar of up to 45 characters.

And my answer is : CREATE TABLE t_genres ( pk_id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY , uk_name VARCHAR(45) NOT NULL UNIQUE KEY;

But its wrong its complaining about the primary key missing ..? What could be a problem. Please assist

Chris Johnson
Chris Johnson
15,048 Points

Hopefully you have figured out the answer by now but you were correct you were just missing the last closing bracket " ) "

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

1 Answer

Adam Womble
Adam Womble
21,619 Points

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

Your MySQL statement is missing a closing parenthesis, before the semicolon. Also, you do not have to specify that the pk_id primary key is not null, as primary keys default to not allowing null values. The use of NOT NULL with the uk_name unique key is still necessary to the challenge, though.

So, after a couple minor tweaks, your MySQL statement should look like this:

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

It's great to take an elaborative approach to writing code in any language while you are still in the construction phase. So, removing something like NOT NULL may seem trivial—or even harmful to understanding the code—but, when it comes to having your SQL statements production-ready, every unnecessary character should be stripped away. I hope that helps!