Cannot pass "Each foreign key column should have the same name as the column it is referencing" in celestial bodies project


I had all the tests pass and had to delete tables and go back to check if everything was in order. Whatever I do, the last test will not pass (Each foreign key column should have the same name as the column it is referencing). I’m so frustrated and I know it must be something inane I am overlooking. Please give me a fresh perspective of any kind and thank you very much in advance. :sweat_smile:

I don’t see anything sticking out from the screen shot @keepreading52. The tests seem to be checking what is being described. It gets all your foreign keys and makes sure the column they are referencing has the same name. There’s probably one that doesn’t have the same name or something. Maybe double check?

If you share a dump of your database using the command in the instructions, I can take a look.

Edit: Actually, I do think you are using the wrong columns there. I think your planets table should have a star_id foreign key that references the star_id from the stars table. In the screen shot, it looks like you created a planet_id foreign key that references the star_id - so the names don’t match there.

2 Likes

Thank you! Will try to make corrections now. Further, before I made purposeful corrections to try and pass the last test all my tests passed. Now the INT test will not pass.

Thank you very much for your time and feedback. I have been reading through all your patient responses in the forums. :slightly_smiling_face:

--
-- 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: asteroid; Type: TABLE; Schema: public; Owner: freecodecamp
--

CREATE TABLE public.asteroid (
    asteroid_id integer NOT NULL,
    name character varying(50),
    magnitude integer NOT NULL,
    major_axis character varying(50),
    discovery_year integer NOT NULL
);


ALTER TABLE public.asteroid OWNER TO freecodecamp;

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

CREATE TABLE public.galaxy (
    galaxy_id integer NOT NULL,
    name character varying(50),
    galaxy_age numeric(20,10),
    galaxy_type text NOT NULL,
    galaxy_distance character varying(50) NOT NULL
);


ALTER TABLE public.galaxy OWNER TO freecodecamp;

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

CREATE TABLE public.moon (
    moon_id integer NOT NULL,
    namer character varying(50) NOT NULL,
    name character varying(50) NOT NULL,
    moon_planet character varying(50) NOT NULL,
    moon_discovery_date numeric 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(50),
    planet_age character varying(50) NOT NULL,
    planet_type character varying(50) NOT NULL,
    planet_distance_in_light_years character varying(50) NOT NULL
);


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(50) NOT NULL,
    magnitude integer NOT NULL,
    star_in_our_solar_system boolean,
    star_within_twenty_light_years boolean
);


ALTER TABLE public.star OWNER TO freecodecamp;

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

INSERT INTO public.asteroid VALUES (1, 'Apophis', 3, '0.922', 2004);
INSERT INTO public.asteroid VALUES (2, 'Vasta', 5, '2.361', 1807);
INSERT INTO public.asteroid VALUES (3, 'Pallas', 6, '2.773', 1802);


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

INSERT INTO public.galaxy VALUES (1, 'Milky Way', 30000.0000000000, 'Spiral', 'two million light years');
INSERT INTO public.galaxy VALUES (2, 'Andromeada', 40000.0000000000, 'Spiral', 'four million light years');
INSERT INTO public.galaxy VALUES (3, 'Antennae Galaxies', 50000.0000000000, 'Spiral', 'three million years');
INSERT INTO public.galaxy VALUES (4, 'Backward Galaxy', 60000.0000000000, 'Spiral', 'four million light years');
INSERT INTO public.galaxy VALUES (5, 'Black Eye', 60000.0000000000, 'Spiral', 'four million light years');
INSERT INTO public.galaxy VALUES (6, 'Bode Galaxy', 80000.0000000000, 'Spiral', 'five million light years');


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

INSERT INTO public.moon VALUES (1, 'Simon Marius', 'Io', 'Jupiter I', 1610);
INSERT INTO public.moon VALUES (2, 'Simon Marius', 'Europa', 'Jupiter', 1610);
INSERT INTO public.moon VALUES (3, 'Simon Marius', 'Ganymede', 'Jupiter III', 1610);
INSERT INTO public.moon VALUES (4, 'Simon Marius', 'Callisto', 'Jupiter IV', 1610);
INSERT INTO public.moon VALUES (5, 'John Herschel', ' Mimas', 'Saturn I', 1789);
INSERT INTO public.moon VALUES (6, 'John Herschel', 'Enceladus', 'Saturn II', 1789);
INSERT INTO public.moon VALUES (7, 'John Herschel', 'Tethys', 'Saturn III', 1684);
INSERT INTO public.moon VALUES (8, 'John Herschel', 'Dione', 'Saturn IV', 1684);
INSERT INTO public.moon VALUES (9, 'John Herschel', 'Rhea', 'Saturn V', 1672);
INSERT INTO public.moon VALUES (10, 'John Herschel', 'Titan', 'Saturn VI', 1655);
INSERT INTO public.moon VALUES (11, 'John Herschel', 'Iapetus', 'Saturn VIII', 1671);
INSERT INTO public.moon VALUES (12, 'William Lassel', 'Hyperion', 'Saturn VII', 1847);
INSERT INTO public.moon VALUES (13, 'John Herschel', 'Ariel', 'Uranus I', 1851);
INSERT INTO public.moon VALUES (14, 'john Herschel', 'Umbriel', 'Uranus II', 1851);
INSERT INTO public.moon VALUES (15, 'John Herschel', 'Titania', 'Uranus III', 1787);
INSERT INTO public.moon VALUES (16, 'John Herschel', 'Oberon', 'Uranus IV', 1787);
INSERT INTO public.moon VALUES (17, 'Asaph Hall', 'Phobos', 'Mars I', 1876);
INSERT INTO public.moon VALUES (18, 'Asaph Hall', 'Deimos', 'Mars II', 1877);
INSERT INTO public.moon VALUES (19, 'Camille Flammarion', 'Triton', 'Neptune I', 1846);
INSERT INTO public.moon VALUES (20, 'Camille Flammarion', 'Amalthea', 'Jupiter V', 1892);


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

INSERT INTO public.planet VALUES (1, 'Mercury', 'four and a half billion years', 'terrestrial', 'one hundred and six million light years');
INSERT INTO public.planet VALUES (2, 'Venus', 'four and a half billion years', 'terrestrial', 'two hundred and forty two million km');
INSERT INTO public.planet VALUES (3, 'Earth', 'four and a half billion years', 'terrestrial', 'not aplicable if you are on earth tbh');
INSERT INTO public.planet VALUES (4, 'Mars', 'four and a half billion years', 'terrestrial', 'one hundred and fifty four million km');
INSERT INTO public.planet VALUES (5, 'Jupiter', 'four and a half billion years', 'gas giant', 'six hundred and twenty one million km');
INSERT INTO public.planet VALUES (6, 'Saturn', 'four and a half billion years', 'gas giant', 'one point three billion km');
INSERT INTO public.planet VALUES (7, 'Uranus', 'four and a half billion years', 'ice giant', 'two billion km');
INSERT INTO public.planet VALUES (8, 'Neptune', 'four and a half billion years', 'ice giant', 'four point three billion km');
INSERT INTO public.planet VALUES (9, 'Ceres', 'four and a half billion years', 'dwarf', 'four hundred and thirteen million km');
INSERT INTO public.planet VALUES (10, 'Pluto', 'four and a half billion years', 'dwarf', 'five billion km');
INSERT INTO public.planet VALUES (11, 'Haumea', 'four and a half billion years', 'dwarf', 'seven billion km');
INSERT INTO public.planet VALUES (12, 'Makemake', 'four and a half billion years', 'dwarf', 'five and a half billion km');
INSERT INTO public.planet VALUES (13, 'unknown', 'four billion years', 'dwarf', 'five billion km');
INSERT INTO public.planet VALUES (14, 'Proxima Centauri b', 'four billion years', 'super Earth sxoplanet', 'four light years');
INSERT INTO public.planet VALUES (15, 'Proxima Centauri c', 'four billion years', 'super Earth exoplanet', 'four billion years');
INSERT INTO public.planet VALUES (16, 'Barnards Star b', 'ten billion years', 'red dwarf star', 'five light years');
INSERT INTO public.planet VALUES (17, 'Ross b', 'nine billion years', 'super Earth exoplanet', 'one light year');
INSERT INTO public.planet VALUES (18, 'Luyten b', 'eight billion years', 'exoplanet', 'twelve light years');
INSERT INTO public.planet VALUES (19, 'Wolf b', 'unknown', 'super Earth exoplanet', 'thirteen light years');
INSERT INTO public.planet VALUES (20, 'Wolf c', 'unknown', 'super Earth exoplanet', 'thirteen light years');


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

INSERT INTO public.star VALUES (1, 'Absolutno', 4, false, false);
INSERT INTO public.star VALUES (2, 'Acamar', 3, false, false);
INSERT INTO public.star VALUES (3, 'Achemar', 3, false, false);
INSERT INTO public.star VALUES (4, 'Achird', 2, false, true);
INSERT INTO public.star VALUES (5, 'Acrab', 3, false, false);
INSERT INTO public.star VALUES (6, 'Acrux', 3, false, false);


--
-- Name: asteroid asteroid_name_key; Type: CONSTRAINT; Schema: public; Owner: freecodecamp
--

ALTER TABLE ONLY public.asteroid
    ADD CONSTRAINT asteroid_name_key UNIQUE (name);


--
-- Name: asteroid asteroid_pkey; Type: CONSTRAINT; Schema: public; Owner: freecodecamp
--

ALTER TABLE ONLY public.asteroid
    ADD CONSTRAINT asteroid_pkey PRIMARY KEY (asteroid_id);


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

ALTER TABLE ONLY public.galaxy
    ADD CONSTRAINT galaxy_id_unique UNIQUE (galaxy_id);


--
-- 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_id_unique; Type: CONSTRAINT; Schema: public; Owner: freecodecamp
--

ALTER TABLE ONLY public.planet
    ADD CONSTRAINT planet_id_unique UNIQUE (planet_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: star fk_galaxy_id; Type: FK CONSTRAINT; Schema: public; Owner: freecodecamp
--

ALTER TABLE ONLY public.star
    ADD CONSTRAINT fk_galaxy_id FOREIGN KEY (star_id) REFERENCES public.galaxy(galaxy_id);


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

ALTER TABLE ONLY public.moon
    ADD CONSTRAINT fk_planet_id FOREIGN KEY (moon_id) REFERENCES public.planet(planet_id);


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

ALTER TABLE ONLY public.planet
    ADD CONSTRAINT fk_star_id FOREIGN KEY (planet_id) REFERENCES public.planet(planet_id);


--
-- PostgreSQL database dump complete
--


Update. It worked! Thank you!!!

1 Like

hello everyone, I am fetching the same problem. Please anyone can look through my dumped SQL and help me finding the bug. Thanks in advance.

--
-- 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: extra_table; Type: TABLE; Schema: public; Owner: freecodecamp
--

CREATE TABLE public.extra_table (
    extra_table_id integer NOT NULL,
    name character varying NOT NULL,
    int_1 integer NOT NULL,
    int_2 integer,
    text_field text,
    boolean_field_1 boolean,
    boolean_field_2 boolean,
    numaric_4_2 numeric(4,2),
    moon_id integer
);


ALTER TABLE public.extra_table OWNER TO freecodecamp;

--
-- Name: extra_table_id_seq; Type: SEQUENCE; Schema: public; Owner: freecodecamp
--

CREATE SEQUENCE public.extra_table_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.extra_table_id_seq OWNER TO freecodecamp;

--
-- Name: extra_table_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: freecodecamp
--

ALTER SEQUENCE public.extra_table_id_seq OWNED BY public.extra_table.extra_table_id;


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

CREATE TABLE public.galaxy (
    galaxy_id integer NOT NULL,
    name character varying NOT NULL,
    int_1 integer NOT NULL,
    int_2 integer,
    numaric_4_2 numeric(4,2),
    text_field text,
    boolean_field_1 boolean,
    boolean_field_2 boolean
);


ALTER TABLE public.galaxy OWNER TO freecodecamp;

--
-- Name: galaxy_id_seq; Type: SEQUENCE; Schema: public; Owner: freecodecamp
--

CREATE SEQUENCE public.galaxy_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.galaxy_id_seq OWNER TO freecodecamp;

--
-- Name: galaxy_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: freecodecamp
--

ALTER SEQUENCE public.galaxy_id_seq OWNED BY public.galaxy.galaxy_id;


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

CREATE TABLE public.moon (
    moon_id integer NOT NULL,
    name character varying NOT NULL,
    int_1 integer NOT NULL,
    int_2 integer,
    numaric_4_2 numeric(4,2),
    text_field text,
    boolean_field_1 boolean,
    boolean_field_2 boolean,
    planet_id integer
);


ALTER TABLE public.moon OWNER TO freecodecamp;

--
-- Name: moon_id_seq; Type: SEQUENCE; Schema: public; Owner: freecodecamp
--

CREATE SEQUENCE public.moon_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.moon_id_seq OWNER TO freecodecamp;

--
-- Name: moon_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: freecodecamp
--

ALTER SEQUENCE public.moon_id_seq OWNED BY public.moon.moon_id;


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

CREATE TABLE public.planet (
    planet_id integer NOT NULL,
    name character varying NOT NULL,
    int_1 integer NOT NULL,
    int_2 integer,
    numaric_4_2 numeric(4,2),
    text_field text,
    boolean_field_1 boolean,
    boolean_field_2 boolean,
    star_id integer
);


ALTER TABLE public.planet OWNER TO freecodecamp;

--
-- Name: planet_id_seq; Type: SEQUENCE; Schema: public; Owner: freecodecamp
--

CREATE SEQUENCE public.planet_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.planet_id_seq OWNER TO freecodecamp;

--
-- Name: planet_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: freecodecamp
--

ALTER SEQUENCE public.planet_id_seq OWNED BY public.planet.planet_id;


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

CREATE TABLE public.star (
    star_id integer NOT NULL,
    name character varying NOT NULL,
    int_1 integer NOT NULL,
    int_2 integer,
    numaric_4_2 numeric(4,2),
    text_field text,
    boolean_field_1 boolean,
    boolean_field_2 boolean,
    galaxy_id integer
);


ALTER TABLE public.star OWNER TO freecodecamp;

--
-- Name: star_id_seq; Type: SEQUENCE; Schema: public; Owner: freecodecamp
--

CREATE SEQUENCE public.star_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.star_id_seq OWNER TO freecodecamp;

--
-- Name: star_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: freecodecamp
--

ALTER SEQUENCE public.star_id_seq OWNED BY public.star.star_id;


--
-- Name: extra_table extra_table_id; Type: DEFAULT; Schema: public; Owner: freecodecamp
--

ALTER TABLE ONLY public.extra_table ALTER COLUMN extra_table_id SET DEFAULT nextval('public.extra_table_id_seq'::regclass);


--
-- Name: galaxy galaxy_id; Type: DEFAULT; Schema: public; Owner: freecodecamp
--

ALTER TABLE ONLY public.galaxy ALTER COLUMN galaxy_id SET DEFAULT nextval('public.galaxy_id_seq'::regclass);


--
-- Name: moon moon_id; Type: DEFAULT; Schema: public; Owner: freecodecamp
--

ALTER TABLE ONLY public.moon ALTER COLUMN moon_id SET DEFAULT nextval('public.moon_id_seq'::regclass);


--
-- Name: planet planet_id; Type: DEFAULT; Schema: public; Owner: freecodecamp
--

ALTER TABLE ONLY public.planet ALTER COLUMN planet_id SET DEFAULT nextval('public.planet_id_seq'::regclass);


--
-- Name: star star_id; Type: DEFAULT; Schema: public; Owner: freecodecamp
--

ALTER TABLE ONLY public.star ALTER COLUMN star_id SET DEFAULT nextval('public.star_id_seq'::regclass);


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

INSERT INTO public.extra_table VALUES (1, 'extra 1', 10, 20, 'i am from extra 1', true, true, 30.25, 1);
INSERT INTO public.extra_table VALUES (2, 'extra 2', 10, 20, 'i am from extra 2', true, true, 30.25, 2);
INSERT INTO public.extra_table VALUES (3, 'extra 3', 10, 20, 'i am from extra 3', true, true, 30.25, 3);
INSERT INTO public.extra_table VALUES (4, 'extra 4', 10, 20, 'i am from extra 4', true, true, 30.25, 4);


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

INSERT INTO public.galaxy VALUES (1, 'galaxy 1', 10, 20, 30.25, 'i am galaxy 1', true, true);
INSERT INTO public.galaxy VALUES (2, 'galaxy 2', 20, 30, 40.25, 'i am galaxy 2', true, true);
INSERT INTO public.galaxy VALUES (3, 'galaxy 3', 30, 40, 50.50, 'i am galaxy 3', true, true);
INSERT INTO public.galaxy VALUES (4, 'galaxy 4', 40, 50, 60.50, 'i am galaxy 4', true, true);
INSERT INTO public.galaxy VALUES (5, 'galaxy 5', 40, 50, 60.50, 'i am galaxy 5', true, true);
INSERT INTO public.galaxy VALUES (6, 'galaxy 6', 40, 50, 60.50, 'i am galaxy 6', true, true);


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

INSERT INTO public.moon VALUES (1, 'moon 1', 10, 20, 30.25, 'i am moon 1', true, true, 1);
INSERT INTO public.moon VALUES (2, 'moon 2', 10, 20, 30.25, 'i am moon 2', true, true, 1);
INSERT INTO public.moon VALUES (3, 'moon 3', 10, 20, 30.25, 'i am moon 3', true, true, 1);
INSERT INTO public.moon VALUES (4, 'moon 4', 10, 20, 30.25, 'i am moon 4', true, true, 1);
INSERT INTO public.moon VALUES (5, 'moon 5', 10, 20, 30.25, 'i am moon 5', true, true, 2);
INSERT INTO public.moon VALUES (6, 'moon 6', 10, 20, 30.25, 'i am moon 6', true, true, 2);
INSERT INTO public.moon VALUES (7, 'moon 7', 10, 20, 30.25, 'i am moon 7', true, true, 2);
INSERT INTO public.moon VALUES (8, 'moon 8', 10, 20, 30.25, 'i am moon 8', true, true, 2);
INSERT INTO public.moon VALUES (9, 'moon 9', 10, 20, 30.25, 'i am moon 9', true, true, 3);
INSERT INTO public.moon VALUES (10, 'moon 10', 10, 20, 30.25, 'i am moon 10', true, true, 3);
INSERT INTO public.moon VALUES (11, 'moon 11', 10, 20, 30.25, 'i am moon 11', true, true, 3);
INSERT INTO public.moon VALUES (12, 'moon 12', 10, 20, 30.25, 'i am moon 12', true, true, 4);
INSERT INTO public.moon VALUES (13, 'moon 13', 10, 20, 30.25, 'i am moon 13', true, true, 4);
INSERT INTO public.moon VALUES (14, 'moon 14', 10, 20, 30.25, 'i am moon 14', true, true, 4);
INSERT INTO public.moon VALUES (15, 'moon 15', 10, 20, 30.25, 'i am moon 15', true, true, 5);
INSERT INTO public.moon VALUES (16, 'moon 16', 10, 20, 30.25, 'i am moon 16', true, true, 5);
INSERT INTO public.moon VALUES (17, 'moon 17', 10, 20, 30.25, 'i am moon 17', true, true, 5);
INSERT INTO public.moon VALUES (18, 'moon 18', 10, 20, 30.25, 'i am moon 18', true, true, 6);
INSERT INTO public.moon VALUES (19, 'moon 19', 10, 20, 30.25, 'i am moon 19', true, true, 6);
INSERT INTO public.moon VALUES (20, 'moon 20', 10, 20, 30.25, 'i am moon 20', true, true, 6);


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

INSERT INTO public.planet VALUES (1, 'planet 1', 10, 20, 30.25, 'i am planet 1', true, true, 1);
INSERT INTO public.planet VALUES (2, 'planet 2', 10, 20, 30.25, 'i am planet 2', true, true, 1);
INSERT INTO public.planet VALUES (3, 'planet 3', 10, 20, 30.25, 'i am planet 3', true, true, 2);
INSERT INTO public.planet VALUES (4, 'planet 4', 10, 20, 30.25, 'i am planet 4', true, true, 2);
INSERT INTO public.planet VALUES (5, 'planet 5', 10, 20, 30.25, 'i am planet 5', true, true, 3);
INSERT INTO public.planet VALUES (6, 'planet 6', 10, 20, 30.25, 'i am planet 6', true, true, 3);
INSERT INTO public.planet VALUES (7, 'planet 7', 10, 20, 30.25, 'i am planet 7', true, true, 4);
INSERT INTO public.planet VALUES (8, 'planet 8', 10, 20, 30.25, 'i am planet 8', true, true, 4);
INSERT INTO public.planet VALUES (9, 'planet 9', 10, 20, 30.25, 'i am planet 9', true, true, 5);
INSERT INTO public.planet VALUES (10, 'planet 10', 10, 20, 30.25, 'i am planet 10', true, true, 5);
INSERT INTO public.planet VALUES (11, 'planet 11', 10, 20, 30.25, 'i am planet 11', true, true, 6);
INSERT INTO public.planet VALUES (12, 'planet 12', 10, 20, 30.25, 'i am planet 12', true, true, 6);


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

INSERT INTO public.star VALUES (1, 'star 1', 10, 20, 30.25, 'i am star 1', true, true, 1);
INSERT INTO public.star VALUES (2, 'star 2', 10, 20, 30.25, 'i am star 2', true, true, 2);
INSERT INTO public.star VALUES (3, 'star 3', 10, 20, 30.25, 'i am star 3', true, true, 3);
INSERT INTO public.star VALUES (4, 'star 4', 10, 20, 30.25, 'i am star 3', true, true, 4);
INSERT INTO public.star VALUES (5, 'star 5', 10, 20, 30.25, 'i am star 5', true, true, 5);
INSERT INTO public.star VALUES (6, 'star 6', 10, 20, 30.25, 'i am star 6', true, true, 6);


--
-- Name: extra_table_id_seq; Type: SEQUENCE SET; Schema: public; Owner: freecodecamp
--

SELECT pg_catalog.setval('public.extra_table_id_seq', 4, true);


--
-- Name: galaxy_id_seq; Type: SEQUENCE SET; Schema: public; Owner: freecodecamp
--

SELECT pg_catalog.setval('public.galaxy_id_seq', 6, true);


--
-- Name: moon_id_seq; Type: SEQUENCE SET; Schema: public; Owner: freecodecamp
--

SELECT pg_catalog.setval('public.moon_id_seq', 20, true);


--
-- Name: planet_id_seq; Type: SEQUENCE SET; Schema: public; Owner: freecodecamp
--

SELECT pg_catalog.setval('public.planet_id_seq', 12, true);


--
-- Name: star_id_seq; Type: SEQUENCE SET; Schema: public; Owner: freecodecamp
--

SELECT pg_catalog.setval('public.star_id_seq', 6, true);


--
-- Name: extra_table extra_table_name_unique; Type: CONSTRAINT; Schema: public; Owner: freecodecamp
--

ALTER TABLE ONLY public.extra_table
    ADD CONSTRAINT extra_table_name_unique UNIQUE (name);


--
-- Name: extra_table extra_table_pkey; Type: CONSTRAINT; Schema: public; Owner: freecodecamp
--

ALTER TABLE ONLY public.extra_table
    ADD CONSTRAINT extra_table_pkey PRIMARY KEY (extra_table_id);


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

ALTER TABLE ONLY public.galaxy
    ADD CONSTRAINT galaxy_name_unique 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_unique; Type: CONSTRAINT; Schema: public; Owner: freecodecamp
--

ALTER TABLE ONLY public.moon
    ADD CONSTRAINT moon_name_unique 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_unique; Type: CONSTRAINT; Schema: public; Owner: freecodecamp
--

ALTER TABLE ONLY public.planet
    ADD CONSTRAINT planet_name_unique 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_unique; Type: CONSTRAINT; Schema: public; Owner: freecodecamp
--

ALTER TABLE ONLY public.star
    ADD CONSTRAINT star_name_unique 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: galaxy text_field_unique; Type: CONSTRAINT; Schema: public; Owner: freecodecamp
--

ALTER TABLE ONLY public.galaxy
    ADD CONSTRAINT text_field_unique UNIQUE (text_field);


--
-- Name: extra_table extra_table_moon_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: freecodecamp
--

ALTER TABLE ONLY public.extra_table
    ADD CONSTRAINT extra_table_moon_id_fkey FOREIGN KEY (moon_id) REFERENCES public.moon(moon_id);


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

ALTER TABLE ONLY public.star
    ADD CONSTRAINT fk_galaxy_id FOREIGN KEY (galaxy_id) REFERENCES public.galaxy(galaxy_id);


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

ALTER TABLE ONLY public.planet
    ADD CONSTRAINT fk_planet_id FOREIGN KEY (star_id) REFERENCES public.star(star_id);


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

ALTER TABLE ONLY public.moon
    ADD CONSTRAINT fk_planet_id FOREIGN KEY (planet_id) REFERENCES public.planet(planet_id);


--
-- PostgreSQL database dump complete
--


1 Like

how it worked. Would you like to share with us.

Hello there

ALTER TABLE galaxy
ADD CONSTRAINT fk_star_id
FOREIGN KEY (galaxy_id)
REFERENCES galaxy(galaxy_id);

This worked for me I hope you can use it in some way. Good luck.

I too was stuck, but not anymore. Your genius will not go unsung!