Celestial Bodies Database

Can someone help me with the last task i don’t know what the problem is.

it is hard to see what is written in the screen shot.
Can you copy and paste the errors or type out the message you want us to see?

It says that any foreign key should have the same name as the key that it is referencing; for example, your moon table should have a planet_id foreign key referencing the planet_id key in the planet table.

However, I see the following line in your screenshot:
...FOREIGN KEY (moon_id) REFERENCES planet(planet_id)

I think that is the source of your problem.

--

-- PostgreSQL database dump

--

-- Dumped from database version 12.9 (Ubuntu 12.9-2.pgdg20.04+1)

-- Dumped by pg_dump version 12.9 (Ubuntu 12.9-2.pgdg20.04+1)

SET statement_timeout = 0;

SET lock_timeout = 0;

SET idle_in_transaction_session_timeout = 0;

SET client_encoding = 'UTF8';

SET standard_conforming_strings = on;

SELECT pg_catalog.set_config('search_path', '', false);

SET check_function_bodies = false;

SET xmloption = content;

SET client_min_messages = warning;

SET row_security = off;

DROP DATABASE universe;

--

-- Name: universe; Type: DATABASE; Schema: -; Owner: freecodecamp

--

CREATE DATABASE universe WITH TEMPLATE = template0 ENCODING = 'UTF8' LC_COLLATE = 'C.UTF-8' LC_CTYPE = 'C.UTF-8';

ALTER DATABASE universe OWNER TO freecodecamp;

\connect universe

SET statement_timeout = 0;

SET lock_timeout = 0;

SET idle_in_transaction_session_timeout = 0;

SET client_encoding = 'UTF8';

SET standard_conforming_strings = on;

SELECT pg_catalog.set_config('search_path', '', false);

SET check_function_bodies = false;

SET xmloption = content;

SET client_min_messages = warning;

SET row_security = off;

SET default_tablespace = '';

SET default_table_access_method = heap;

--

-- Name: earth; Type: TABLE; Schema: public; Owner: freecodecamp

--

CREATE TABLE public.earth (

earth_id integer NOT NULL,

name character varying NOT NULL,

has_life boolean,

people_living numeric,

name_id integer

);

ALTER TABLE public.earth OWNER TO freecodecamp;

--

-- Name: galaxy; Type: TABLE; Schema: public; Owner: freecodecamp

--

CREATE TABLE public.galaxy (

galaxy_id integer NOT NULL,

name character varying NOT NULL,

has_life boolean,

name_id integer NOT NULL,

notes text

);

ALTER TABLE public.galaxy OWNER TO freecodecamp;

--

-- Name: moon; Type: TABLE; Schema: public; Owner: freecodecamp

--

CREATE TABLE public.moon (

moon_id integer NOT NULL,

name character varying NOT NULL,

has_life boolean,

distance integer,

name_id integer NOT NULL

);

ALTER TABLE public.moon OWNER TO freecodecamp;

--

-- Name: planet; Type: TABLE; Schema: public; Owner: freecodecamp

--

CREATE TABLE public.planet (

planet_id integer NOT NULL,

name character varying NOT NULL,

has_life boolean,

name_id integer NOT NULL,

notes text

);

ALTER TABLE public.planet OWNER TO freecodecamp;

--

-- Name: star; Type: TABLE; Schema: public; Owner: freecodecamp

--

CREATE TABLE public.star (

star_id integer NOT NULL,

name character varying NOT NULL,

has_life boolean,

distance integer,

discription text,

name_id integer NOT NULL

);

ALTER TABLE public.star OWNER TO freecodecamp;

--

-- Data for Name: earth; Type: TABLE DATA; Schema: public; Owner: freecodecamp

--

INSERT INTO public.earth VALUES (1, 'i', false, 22, 1);

INSERT INTO public.earth VALUES (2, 'd', false, 222, 2);

INSERT INTO public.earth VALUES (3, 'dd', false, 2322, 3);

--

-- Data for Name: galaxy; Type: TABLE DATA; Schema: public; Owner: freecodecamp

--

INSERT INTO public.galaxy VALUES (1, 'pluto', true, 1, 'big');

INSERT INTO public.galaxy VALUES (2, 'mars', false, 2, 'nice');

INSERT INTO public.galaxy VALUES (3, 'earth', true, 3, 'water');

INSERT INTO public.galaxy VALUES (4, 'saturnus', false, 4, 'ring');

INSERT INTO public.galaxy VALUES (5, 'sun', false, 5, 'heat');

INSERT INTO public.galaxy VALUES (6, 'venus', false, 6, 'heat');

INSERT INTO public.galaxy VALUES (7, 'saturn', true, 7, 'hot');

INSERT INTO public.galaxy VALUES (8, 'SK', false, 8, 'o');

INSERT INTO public.galaxy VALUES (9, 'YY', true, 9, 'd');

INSERT INTO public.galaxy VALUES (10, 'IK', false, 10, 's');

INSERT INTO public.galaxy VALUES (11, 'jfhfhf', false, 11, 'd');

INSERT INTO public.galaxy VALUES (12, 'ywhdk', false, 12, 'dd');

INSERT INTO public.galaxy VALUES (13, 'i', true, 13, 'fe');

INSERT INTO public.galaxy VALUES (14, 'z', true, 14, 'fde');

INSERT INTO public.galaxy VALUES (15, 'zf', true, 15, 'ffde');

INSERT INTO public.galaxy VALUES (16, 'zff', true, 16, 'fvfde');

INSERT INTO public.galaxy VALUES (17, 'zdff', true, 17, 'fcvfde');

INSERT INTO public.galaxy VALUES (18, 'zsdff', true, 18, 'fcvfde');

INSERT INTO public.galaxy VALUES (19, 'zdsdff', true, 19, 'fcvfde');

INSERT INTO public.galaxy VALUES (20, 'zcdsdff', true, 20, 'fcvfde');

INSERT INTO public.galaxy VALUES (21, 'iko', false, 21, 'pkp');

--

-- Data for Name: moon; Type: TABLE DATA; Schema: public; Owner: freecodecamp

--

INSERT INTO public.moon VALUES (1, 'spaceX', true, 5000, 1);

INSERT INTO public.moon VALUES (2, 'rocket', true, 888, 2);

INSERT INTO public.moon VALUES (3, 'SK', false, 333, 3);

INSERT INTO public.moon VALUES (4, 'YY', false, 444, 4);

INSERT INTO public.moon VALUES (5, 'IK', false, 5555, 5);

INSERT INTO public.moon VALUES (6, 'bored', true, 896, 6);

INSERT INTO public.moon VALUES (7, 'hh', false, 5555, 7);

INSERT INTO public.moon VALUES (9, 'hrh', false, 585955, 9);

INSERT INTO public.moon VALUES (10, 'hrgh', false, 5485955, 10);

INSERT INTO public.moon VALUES (11, 'zz', true, 333, 11);

INSERT INTO public.moon VALUES (12, 'zdz', true, 3233, 12);

INSERT INTO public.moon VALUES (13, 'zddz', true, 32333, 13);

INSERT INTO public.moon VALUES (14, 'zcddz', true, 323343, 14);

INSERT INTO public.moon VALUES (15, 'zfcddz', true, 3523343, 15);

INSERT INTO public.moon VALUES (16, 'zgfcddz', true, 35233643, 16);

INSERT INTO public.moon VALUES (17, 'zgbfcddz', true, 357233643, 17);

INSERT INTO public.moon VALUES (18, 'zngbfcddz', true, 35872343, 18);

INSERT INTO public.moon VALUES (19, 'zngbbfcddz', true, 358723483, 19);

INSERT INTO public.moon VALUES (20, 'zngbbfdcdbdz', true, 358723483, 20);

INSERT INTO public.moon VALUES (21, 'zngbbfdcddbdz', true, 358723483, 21);

--

-- Data for Name: planet; Type: TABLE DATA; Schema: public; Owner: freecodecamp

--

INSERT INTO public.planet VALUES (1, 'venus', false, 1, 'km');

INSERT INTO public.planet VALUES (2, 'sun', false, 2, 'heat');

INSERT INTO public.planet VALUES (3, 'earth', true, 3, 'life');

INSERT INTO public.planet VALUES (4, 'pluto', true, 4, 'nice');

INSERT INTO public.planet VALUES (5, 'cloud', false, 5, 'great');

INSERT INTO public.planet VALUES (6, 'big', true, 6, 'good');

INSERT INTO public.planet VALUES (7, 'mosh', true, 7, 'p');

INSERT INTO public.planet VALUES (8, 'jfjfj', false, 8, 'hdhdh');

INSERT INTO public.planet VALUES (9, 'dhd', false, 9, 'jfjjf');

INSERT INTO public.planet VALUES (10, 'jdgd', false, 10, 'ksik');

INSERT INTO public.planet VALUES (12, 'dhddd', false, 12, 'jfdddjjf');

INSERT INTO public.planet VALUES (13, 'z', true, 13, 'q');

INSERT INTO public.planet VALUES (14, 'zd', true, 14, 'qf');

INSERT INTO public.planet VALUES (15, 'zvd', true, 15, 'qff');

INSERT INTO public.planet VALUES (16, 'zvvd', true, 16, 'qvff');

INSERT INTO public.planet VALUES (17, 'zvvvd', true, 17, 'qvvff');

INSERT INTO public.planet VALUES (18, 'zhvvvd', true, 18, 'qhvvff');

INSERT INTO public.planet VALUES (19, 'zhfvvvd', true, 19, 'qbhvvff');

INSERT INTO public.planet VALUES (20, 'zdhfvvvd', true, 20, 'qcbhvvff');

INSERT INTO public.planet VALUES (11, 'zcdhfvvvd', true, 11, 'qcbcchvvff');

INSERT INTO public.planet VALUES (21, 'sk', false, 21, 'ps');

--

-- Data for Name: star; Type: TABLE DATA; Schema: public; Owner: freecodecamp

--

INSERT INTO public.star VALUES (1, 'star', false, 50, 'far', 1);

INSERT INTO public.star VALUES (2, 'miep', true, 1000, 'hi', 2);

INSERT INTO public.star VALUES (3, 'wok', true, 90, 'ik', 3);

INSERT INTO public.star VALUES (4, 'MOK', false, 89999, 'dw', 4);

INSERT INTO public.star VALUES (5, 'kok', false, 3333, 'dh', 5);

INSERT INTO public.star VALUES (6, 'SK', true, 7474, 'df', 6);

INSERT INTO public.star VALUES (7, 'YY', true, 8585, 'yas', 7);

INSERT INTO public.star VALUES (8, 'IK', true, 555, 'IN', 8);

INSERT INTO public.star VALUES (9, 'JSBSH', false, 578, 'jddn', 9);

INSERT INTO public.star VALUES (10, 'gdgdg', true, 587456, 'hstwb', 10);

INSERT INTO public.star VALUES (11, 'jdjhdh', false, 888, 'dfsh', 11);

INSERT INTO public.star VALUES (12, 'jdjhddjdh', false, 888, 'dfsh', 12);

INSERT INTO public.star VALUES (13, 'z', false, 999, 'qq', 13);

INSERT INTO public.star VALUES (14, 'zd', false, 9399, 'q3q', 14);

INSERT INTO public.star VALUES (15, 'zfd', false, 93699, 'qg3q', 15);

INSERT INTO public.star VALUES (16, 'zffd', false, 943699, 'qgg3q', 16);

INSERT INTO public.star VALUES (17, 'zvffd', false, 9343699, 'qfgg3q', 17);

INSERT INTO public.star VALUES (18, 'zvvffd', false, 94343699, 'qffgg3q', 18);

INSERT INTO public.star VALUES (19, 'zvdvffd', false, 934343699, 'qvffgg3q', 19);

INSERT INTO public.star VALUES (20, 'zcvdvffd', false, 93343699, 'qvvffgg3q', 20);

INSERT INTO public.star VALUES (21, 'ddd', true, 22, 'lll', 21);

--

-- Name: earth earth_name_key; Type: CONSTRAINT; Schema: public; Owner: freecodecamp

--

ALTER TABLE ONLY public.earth

ADD CONSTRAINT earth_name_key UNIQUE (name);

--

-- Name: earth earth_pkey; Type: CONSTRAINT; Schema: public; Owner: freecodecamp

--

ALTER TABLE ONLY public.earth

ADD CONSTRAINT earth_pkey PRIMARY KEY (earth_id);

--

-- Name: galaxy galaxy_name_key; Type: CONSTRAINT; Schema: public; Owner: freecodecamp

--

ALTER TABLE ONLY public.galaxy

ADD CONSTRAINT galaxy_name_key UNIQUE (name);

--

-- Name: galaxy galaxy_pkey; Type: CONSTRAINT; Schema: public; Owner: freecodecamp

--

ALTER TABLE ONLY public.galaxy

ADD CONSTRAINT galaxy_pkey PRIMARY KEY (galaxy_id);

--

-- Name: moon moon_name_key; Type: CONSTRAINT; Schema: public; Owner: freecodecamp

--

ALTER TABLE ONLY public.moon

ADD CONSTRAINT moon_name_key UNIQUE (name);

--

-- Name: moon moon_pkey; Type: CONSTRAINT; Schema: public; Owner: freecodecamp

--

ALTER TABLE ONLY public.moon

ADD CONSTRAINT moon_pkey PRIMARY KEY (moon_id);

--

-- Name: planet planet_name_key; Type: CONSTRAINT; Schema: public; Owner: freecodecamp

--

ALTER TABLE ONLY public.planet

ADD CONSTRAINT planet_name_key UNIQUE (name);

--

-- Name: planet planet_pkey; Type: CONSTRAINT; Schema: public; Owner: freecodecamp

--

ALTER TABLE ONLY public.planet

ADD CONSTRAINT planet_pkey PRIMARY KEY (planet_id);

--

-- Name: star star_name_key; Type: CONSTRAINT; Schema: public; Owner: freecodecamp

--

ALTER TABLE ONLY public.star

ADD CONSTRAINT star_name_key UNIQUE (name);

--

-- Name: star star_pkey; Type: CONSTRAINT; Schema: public; Owner: freecodecamp

--

ALTER TABLE ONLY public.star

ADD CONSTRAINT star_pkey PRIMARY KEY (star_id);

--

-- Name: moon moon_moon_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: freecodecamp

--

ALTER TABLE ONLY public.moon

ADD CONSTRAINT moon_moon_id_fkey FOREIGN KEY (moon_id) REFERENCES public.planet(planet_id);

--

-- Name: planet planet_planet_id_fkey1; Type: FK CONSTRAINT; Schema: public; Owner: freecodecamp

--

ALTER TABLE ONLY public.planet

ADD CONSTRAINT planet_planet_id_fkey1 FOREIGN KEY (planet_id) REFERENCES public.planet(planet_id);

--

-- Name: star star_star_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: freecodecamp

--

ALTER TABLE ONLY public.star

ADD CONSTRAINT star_star_id_fkey FOREIGN KEY (star_id) REFERENCES public.galaxy(galaxy_id);

--

-- PostgreSQL database dump complete

--

error = SUBTASKS 1.1 :24 Each foreign key column should share a name with the column it is referencing.

the two related columns should have the same name

same here

it seems like you put the moon_id in the moon table to reference the planet_id in the planet table and so on, but the moon table should have a planet_id column so that you can say to which planet it belongs to

1 Like

Thanks for the solution!!

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.