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?
hbar1st
September 26, 2022, 1:00pm
2
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.
hbar1st
September 26, 2022, 1:05pm
4
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)
hbar1st
September 26, 2022, 1:13pm
6
What is your OS? (Windows? Etc)
hbar1st
September 26, 2022, 1:21pm
8
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 "public.properties"
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 | | |
Indexes:
"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
then
run \d properties
hbar1st
September 26, 2022, 1:28pm
9
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
1 Like