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 trialOtec Perez Glass
7,678 PointsIs not Working!
The requirement is
Now recreate the MEMBERS table with the new FAVORITE_ROCK_ID column, and make sure it has a foreign key constraint to the ID column of the ROCKS table. The columns should now be: ID, FIRST_NAME, LAST_NAME, and FAVORITE_ROCK_ID.
My Solution was
CREATE TABLE MEMBERS (
ID PRIMARY KEY,
FIST_NAME,
LAST_NAME,
FAVORITE_ROCK_ID REFERENCES ROCKS(ID) );
Also tried different ways like
CREATE TABLE MEMBERS(
ID INTEGER PRIMARY KEY,
FIST_NAME VARCHAR(255),
LAST_NAME VARCHAR(255),
FAVORITE_ROCK_ID REFERENCES ROCKS(ID) );
The Error message is
Make sure you're creating all 4 columns: id, first_name, last_name, and favorite_rock_id. But I already have them
3 Answers
ivana kantnerova
15,932 Pointsmaybe ... FIST_NAME vs. first_name and data type "int" should be in FAVORITE_ROCK_ID REFERENCES ROCKS(ID) );
like MySQL:
CREATE TABLE Orders ( OrderID int NOT NULL, OrderNumber int NOT NULL, PersonID int, PRIMARY KEY (OrderID), FOREIGN KEY (PersonID) REFERENCES Persons(PersonID) );
or SQL Server / Oracle / MS Access:
CREATE TABLE Orders ( OrderID int NOT NULL PRIMARY KEY, OrderNumber int NOT NULL, PersonID int FOREIGN KEY REFERENCES Persons(PersonID) ); from https://www.w3schools.com/sql/sql_foreignkey.asp
ivana kantnerova
15,932 Pointsyou forgot keyword "foreign key", and date type.. try this CREATE TABLE MEMBERS( id int NOT NULL PRIMARY KEY, first_name varchar NOT NULL, last Name varchar NOT NULL, FAVORITE_ROCK_ID int foreign key REFERENCES ROCKS(ID) ); or this CREATE TABLE MEMBERS( id int NOT NULL PRIMARY KEY, first_name varchar NOT NULL, last Name varchar NOT NULL, FAVORITE_ROCK_ID int, foreign key(FAVORITE_ROCK_ID) REFERENCES ROCKS(ID) );
Otec Perez Glass
7,678 PointsThanks for the help!
Roxanne Reyes
9,006 PointsI tried your code, but it still doesn't work.
Otec Perez Glass
7,678 PointsOtec Perez Glass
7,678 PointsThanks for the information hope your are doing well ivana kantnerova