Insert into multiple rows error - Periodic Table Database - Build a Periodic Table Database

Tell us what’s happening:
While attempting the task: ’ Your properties table should have a type_id foreign key column that references the type_id column from the types table. It should be an INT with the NOT NULL constraint’ (see screenshot)

New column was easily made using: alter table properties add column type_id int;

To add values into the new column (and later set the column to NOT NULL) with 9 rows, I tried the following insert data code (insert into one specific column) which is somehow failing by trying to add values to multiple columns. Not sure how to resolve this.

Code so far
insert into properties(type_id) values(3),(3),(1),(1),(2),(3),(3),(3),(2);

Error upon code fail:
ERROR: null value in column "atomic_number" violates not-null constraint DETAIL: Failing row contains (null, null, null, null, null, 3).

Screenshot:

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36

Challenge: Periodic Table Database - Build a Periodic Table Database

Link to the challenge:

1 Like

The error is telling you that you are trying to add nulls into columns that do not accept nulls.

Why are you adding only one column and ignoring the rest?

1 Like

Other columns already have data. To avoid adding into other other columns, I believe properties(type_id) targets only the type_id column. But it seems I’m mistaken.

the other columns are empty because you haven’t given any data in the insert. your insert is effectively saying that you want to add empty rows and just fill one cell in each row.

if on the other hand you are trying to update existing rows, then use sql update instead of insert.

1 Like