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

Bob McKay
Bob McKay
5,814 Points

Baffled by MySQL Create Table

Hi all,

I'm sure I'm doing something stupid (or not doing something smart!) but I'm baffled by a really simple step in the MySQL foundation course - I'm being asked to do the following:

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.

I am entering this:

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

But I'm getting this error returned (and I'm failing):

43df43e0-46c7-4f61-abf4-8a5d68595ae4.rb:38:in eval': wrong number of arguments (at least 1) (ArgumentError) from (eval):11:in<main>' from 43df43e0-46c7-4f61-abf4-8a5d68595ae4.rb:38:in eval' from 43df43e0-46c7-4f61-abf4-8a5d68595ae4.rb:38:in<main>'

Any ideas? Been banging my head against it for a while now!

Thanks

Bob

3 Answers

Bob McKay
Bob McKay
5,814 Points

Sod it - completely missed the 'unique' specification.

Is your issue resolved, hun?

I don't see anything wrong with your code but I did spruce it up a bit. Maybe try this?

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

Let me know if this works out for you. :)

Bob McKay
Bob McKay
5,814 Points

Yes all sorted thanks Jessica, I was missing 'UNIQUE' from the SQL (I just didn't see it in the instructions - my coding was ok, it was my English comprehension at fault! :-D

C'est la vie. ;)

Good luck in your adventures.