question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Issue with Primary Key name when getting the 5th table with primary key

See original GitHub issue

Affected page

https://www.freecodecamp.org/learn/relational-database/build-a-celestial-bodies-database-project/build-a-celestial-bodies-database

Your code

My SQL file used
--
-- PostgreSQL database dump
--

-- Dumped from database version 14.2 (Ubuntu 14.2-1.pgdg20.04+1+b1)
-- Dumped by pg_dump version 14.2 (Ubuntu 14.2-1.pgdg20.04+1+b1)

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: galaxy; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.galaxy (
    galaxy_id integer NOT NULL,
    name character varying(60) NOT NULL,
    galaxy_type_id integer,
    number_of_stars integer,
    constellation character varying(70)
);


ALTER TABLE public.galaxy OWNER TO postgres;

--
-- Name: galaxy_galaxy_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

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


ALTER TABLE public.galaxy_galaxy_id_seq OWNER TO postgres;

--
-- Name: galaxy_galaxy_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

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


--
-- Name: galaxy_type; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.galaxy_type (
    galaxy_type_id integer NOT NULL,
    name character varying(60) NOT NULL,
    is_spherical boolean,
    is_disk boolean,
    is_spiral boolean
);


ALTER TABLE public.galaxy_type OWNER TO postgres;

--
-- Name: galaxy_type_galaxy_type_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

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


ALTER TABLE public.galaxy_type_galaxy_type_id_seq OWNER TO postgres;

--
-- Name: galaxy_type_galaxy_type_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE public.galaxy_type_galaxy_type_id_seq OWNED BY public.galaxy_type.galaxy_type_id;


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

CREATE TABLE public.moon (
    moon_id integer NOT NULL,
    name character varying(60) NOT NULL,
    planet_id integer,
    temperature_in_kelvins numeric,
    discovered_date date
);


ALTER TABLE public.moon OWNER TO postgres;

--
-- Name: moon_moon_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

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


ALTER TABLE public.moon_moon_id_seq OWNER TO postgres;

--
-- Name: moon_moon_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

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


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

CREATE TABLE public.planet (
    planet_id integer NOT NULL,
    name character varying(60) NOT NULL,
    star_id integer,
    escape_velocity integer,
    num_satellites integer,
    orbit_period_in_days integer,
    description text
);


ALTER TABLE public.planet OWNER TO postgres;

--
-- Name: planet_planet_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

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


ALTER TABLE public.planet_planet_id_seq OWNER TO postgres;

--
-- Name: planet_planet_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

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


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

CREATE TABLE public.star (
    star_id integer NOT NULL,
    name character varying(60) NOT NULL,
    galaxy_id integer,
    mass integer,
    escape_velocity_m_per_s integer
);


ALTER TABLE public.star OWNER TO postgres;

--
-- Name: star_star_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

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


ALTER TABLE public.star_star_id_seq OWNER TO postgres;

--
-- Name: star_star_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

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


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

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


--
-- Name: galaxy_type galaxy_type_id; Type: DEFAULT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.galaxy_type ALTER COLUMN galaxy_type_id SET DEFAULT nextval('public.galaxy_type_galaxy_type_id_seq'::regclass);


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

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


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

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


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

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


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

COPY public.galaxy (galaxy_id, name, galaxy_type_id, number_of_stars, constellation) FROM stdin;
1	Milky Way	1	100	Sagittarius
2	Canis Major Dwarf	4	1	Canis Major
3	Cartwheel Galaxy	3	\N	Sculptor
4	NGC 2787	3	\N	Ursa Minor
5	NGC 4608	3	\N	Virgo
6	Messier 108	1	\N	Ursa Minor
7	Messier 95	1	\N	Leo
\.


--
-- Data for Name: galaxy_type; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.galaxy_type (galaxy_type_id, name, is_spherical, is_disk, is_spiral) FROM stdin;
1	Barred Spiral Galaxy	f	t	t
2	Dwarf spheroidal galaxy	t	f	f
3	Lenticular Galaxy	f	t	f
4	Irregular Galaxy	f	f	f
\.


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

COPY public.moon (moon_id, name, planet_id, temperature_in_kelvins, discovered_date) FROM stdin;
1	Ganymede	1	110	1610-01-07
2	Titan	2	93	1655-03-25
3	Callisto	1	134	1610-01-07
4	Io	1	110	1610-01-08
5	Moon	3	250	\N
6	Europa	1	102	1610-01-08
7	Triton	4	38	1846-10-10
8	Titania	5	70	1787-01-11
9	Rhea	2	53	1672-12-23
10	Oberon	5	75	1787-01-11
11	Iapetus	2	110	1671-10-25
12	Umbriel	5	\N	1851-10-24
13	Ariel	5	\N	1851-10-24
14	Dione	2	\N	1684-03-21
15	Tethys	2	86	1684-03-21
16	Enceladus	2	75	1789-08-28
17	Miranda	5	60	1948-02-16
18	Proteus	4	51	1989-06-16
19	Mimas	2	64	1789-09-17
20	Hyperion	2	93	1848-09-16
21	Phoebe	2	73	1899-03-17
22	Janus	2	76	1966-12-15
23	Epimetheus	2	78	1966-12-18
24	Prometheus	2	74	1980-10-01
\.


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

COPY public.planet (planet_id, name, star_id, escape_velocity, num_satellites, orbit_period_in_days, description) FROM stdin;
1	Jupiter	1	59	80	4332	\N
2	Saturn	1	35	83	10759	\N
4	Neptune	1	23	14	60195	\N
5	Uranus	1	21	27	30688	\N
6	Venus	1	10	0	224	\N
7	Mars	1	5	2	779	\N
8	Mercury	1	4	0	87	\N
9	Jupiter	7	\N	\N	\N	\N
10	HIP 11915 b	8	\N	\N	\N	\N
11	GJ 687 b	9	\N	\N	\N	\N
12	GJ 687 c	9	\N	\N	\N	\N
3	Earth	1	11	1	365	Human Planet
\.


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

COPY public.star (star_id, name, galaxy_id, mass, escape_velocity_m_per_s) FROM stdin;
1	Sun	1	\N	617
2	Barnards Star	1	\N	\N
3	Wolf 359	1	\N	\N
4	Lalande 21185	1	\N	\N
5	Ross 154	1	\N	\N
6	Ross 248	1	\N	\N
7	OGLE-2014-BLG-0124L	1	\N	\N
8	HIP 11915	1	\N	\N
9	GJ 687	1	\N	\N
\.


--
-- Name: galaxy_galaxy_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
--

SELECT pg_catalog.setval('public.galaxy_galaxy_id_seq', 7, true);


--
-- Name: galaxy_type_galaxy_type_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
--

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


--
-- Name: moon_moon_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
--

SELECT pg_catalog.setval('public.moon_moon_id_seq', 24, true);


--
-- Name: planet_planet_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
--

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


--
-- Name: star_star_id_seq; Type: SEQUENCE SET; Schema: public; Owner: postgres
--

SELECT pg_catalog.setval('public.star_star_id_seq', 9, true);


--
-- Name: galaxy galaxy_constraint; Type: CONSTRAINT; Schema: public; Owner: postgres
--

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


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

ALTER TABLE ONLY public.galaxy
    ADD CONSTRAINT galaxy_pkey PRIMARY KEY (galaxy_id);


--
-- Name: galaxy_type galaxy_typeconstraint; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.galaxy_type
    ADD CONSTRAINT galaxy_typeconstraint UNIQUE (galaxy_type_id);


--
-- Name: moon moon_constraint; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.moon
    ADD CONSTRAINT moon_constraint UNIQUE (moon_id);


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

ALTER TABLE ONLY public.moon
    ADD CONSTRAINT moon_pkey PRIMARY KEY (moon_id);


--
-- Name: planet planet_constraint; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.planet
    ADD CONSTRAINT planet_constraint UNIQUE (planet_id);


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

ALTER TABLE ONLY public.planet
    ADD CONSTRAINT planet_pkey PRIMARY KEY (planet_id);


--
-- Name: star star_constraint; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.star
    ADD CONSTRAINT star_constraint UNIQUE (star_id);


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

ALTER TABLE ONLY public.star
    ADD CONSTRAINT star_pkey PRIMARY KEY (star_id);


--
-- Name: galaxy galaxy_galaxy_type_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.galaxy
    ADD CONSTRAINT galaxy_galaxy_type_id_fkey FOREIGN KEY (galaxy_type_id) REFERENCES public.galaxy_type(galaxy_type_id);


--
-- Name: moon moon_planet_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

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


--
-- Name: planet planet_star_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

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


--
-- Name: star star_galaxy_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

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


--
-- PostgreSQL database dump complete
--

then ran the following command after realizing the I need a PK for all tables alter table galaxy_type add constraint galaxyTypePkey primary key (galaxy_type_id);

Expected behavior

I expected the primary key to be noticed. I didn’t realize there was an expected constraint name for the pkey

Screenshots

System

  • Device: [e.g. iPhone6, Laptop]
  • OS: [e.g. iOS 14, Windows 10, Ubuntu 20.4]
  • Browser: [e.g. chrome, safari]
  • Version: [e.g. 22]

Additional context

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ieahleencommented, Oct 18, 2022

@UnicornAriel1 @getcoder-top We typically do not assign issues. Instead, we accept the first pull request that comprehensively solves the issue.

Issues labelled with help wanted or first timers only are open for contributions.

Please make sure you read our guidelines for contributing. We prioritize contributors following the instructions in our guide. Join us in our chat room or the forum if you need help contributing - our community will be happy to assist you.

the build celestial database repo is this one: https://github.com/freeCodeCamp/learn-celestial-bodies-database

0reactions
moT01commented, Oct 28, 2022

I cannot reproduce this. I renamed some of my constraints and all the tests passed for me. I also do not see any tests that are checking the name of constraints, so I am going to close this.

If someone thinks there’s still an issue here, feel free to bring it up and we can reopen it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Database Normalization and Primary Keys
Primary keys are a database constraint allowing us to implement the first and second normal forms. The first rule to follow to reach...
Read more >
The great primary-key debate | TechRepublic
Database developers often disagree about whether it's better to use naturally occurring data or meaningless values as a table's primary key.
Read more >
ALTER PRIMARY KEY | CockroachDB Docs
Use the ALTER PRIMARY KEY statement to change the primary key of a table. ... The name of the column(s) that you want...
Read more >
Combined primary key vs single integer primary key large table
Have a look at Why use multiple columns as primary keys (composite primary key). It looks like the consensus there is what we...
Read more >
Rename primary key - Ask TOM - Oracle
Hi Tom, I inherited a database application with a lot of primary keys created with sys name, such as SYS_C002383. I want to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found