Build a periodic table

One of the points:
" You should set the atomic_number column from the properties table as a foreign key that references the column of the same name in the elements table"

I typed: ALTER TABLE properties ADD COLUMN atomic_number INT REFERENCES elements(atomic_number);

text is displayed: ERROR column “atomic_number” of relation “properties” already exists

None of the tables have a foreign key. What could be wrong?

Can you get the schema of the table? (Such as from the psql terminal)?

A window is displayed: The terminal has no selection to copy.

I’m not sure I understood your message. Can you show me your screen at the moment? Maybe I can guide you.

Printscreen is not working on my computer.

properties column:
Indexes: "properties_pkey PRIMARY KEY, btree (atomic_number)
“properties_atomic_number_key” UNIQUE CONSTRAINT , btree (atomic_number)

What is your OS? (Windows? Etc)

                           I have  Windows 10 Pro.

okay, I am also on windows. I use a tool called “Snipping Tool” so you can maybe look at installing it so you can take screen captures.

The piece of information I was hoping you could print out was something like the following:

periodic_table=> \d properties
                       Table ""
    Column     |         Type          | Collation | Nullable | Default 
 atomic_number | integer               |           | not null | 
 type          | character varying(30) |           |          | 
 weight        | numeric(9,6)          |           | not null | 
 melting_point | numeric               |           |          | 
 boiling_point | numeric               |           |          | 
    "properties_pkey" PRIMARY KEY, btree (atomic_number)
    "properties_atomic_number_key" UNIQUE CONSTRAINT, btree (atomic_number)

you can get it by opening a terminal and running this:
psql --username=freecodecamp --dbname=periodic_table
run \d properties

if your table already has a column called “atomic_number” then I think you need this type of statement:

ALTER TABLE properties
    ADD FOREIGN KEY (atomic_number) REFERENCES elements(atomic_number);

Try that, and hopefully it will work.

Thank you, it works fine now :slight_smile:

1 Like