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 Database Foundations Creating Tables and Manipulating Data with SQL Inserting, Updating and Deleting Rows

Alex Martino
Alex Martino
367 Points

Problem with null and a column in SQL

Hello. I'm getting this error when I use the code in the video about populating tables with SQL.

Code: Insert into movies values ("Avatar", 2009), (Null, "Avatar 2");

13:29:06 Insert into movies values ("Avatar", 2009), (Null, "Avatar 2") 2 row(s) affected, 2 warning(s): 1048 Column 'title' cannot be null 1366 Incorrect integer value: 'Avatar 2' for column 'year' at row 2 Records: 2 Duplicates: 0 Warnings: 2 0.0010 sec

2 Answers

LaVaughn Haynes
LaVaughn Haynes
12,397 Points

For the table that you are using, the title should be a string and the year should be an integer. You are trying to insert a null value as the title instead of a string, and you are trying to insert the string "Avatar 2" for the year. You need to insert data in the appropriate order when using

INSERT INTO movies VALUES(title, year);

You are doing this

INSERT INTO movies VALUES(title, year), (year, title);

Note that you switched the order in the second set of data. You need to keep them in the same order

INSERT INTO movies VALUES(title, year), (title, year);

OR

INSERT INTO movies (year, title) VALUES(year, title), (year, title);