Tell us what’s happening:
Fails ‘all tables should have a primary key’ but using \d on each table shows they all do have a primary key. How do I proceed?
_name JOIN information_schema.key_column_usage kcu ON tc.constraint_name = kcu.constraint_name WHERE t.table_schema = 'public' AND tc.constraint_type = 'PRIMARY KEY';
+---------------+-------------+
| table_name | primary_key |
+---------------+-------------+
| constellation | id |
| constellation | star_id |
| galaxy | galaxy_id |
| moon | moon_id |
| planet | planet_id |
| star | star_id |
+---------------+——————+```
### Your code so far
### Your browser information:
User Agent is: <code>Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.1 Safari/605.1.15 Ddg/26.1</code>
### Challenge Information:
Build a Celestial Bodies Database - Build a Celestial Bodies Database
https://www.freecodecamp.org/learn/relational-databases-v9/lab-celestial-bodies-database/lab-celestial-bodies-database
ILM
January 8, 2026, 8:24am
2
read again the user story on the primary key names, iirc it’s specific
I fixed the id column on constellation and am still getting the same error: All tables should have a primary key.
ILM
January 8, 2026, 3:29pm
4
can you share your dump file?
ILM
January 8, 2026, 3:45pm
6
SET default_tablespace = '';
SET default_table_access_method = heap;
--
-- Name: constellation; Type: TABLE; Schema: public; Owner: freecodecamp
--
CREATE TABLE public.constellation (
name character varying(30),
id integer NOT NULL,
star_id integer NOT NULL,
new_column character varying(10)
);
ALTER TABLE public.constellation OWNER TO freecodecamp;
--
-- Name: constellation_id_seq; Type: SEQUENCE; Schema: public; Owner: freecodecamp
--
here I see id not constellation_id for column name
and I think that your primary key for constellation should also be constellation_id, not two columns
I forgot to push the updated universe.sql to GitHub, have now done so. And I need constellation’s primary key to be composite, as each constellation can (must) have more than one star associated with it.
Here’s the GitHub link again:
https://github.com/dhorowitz001/learn-celestial-bodies-database.git
ILM
January 8, 2026, 4:19pm
8
I am not sure you can pass the tests with that setup
it expects the same number of primary key columns and tables
it(':3 All tables should have a primary key', async () => {
const queryPrimaryKeys = `SELECT c.column_name, c.ordinal_position FROM information_schema.key_column_usage AS c LEFT JOIN information_schema.table_constraints AS t ON t.constraint_name = c.constraint_name WHERE t.constraint_type = 'PRIMARY KEY'`;
const queryTables = `SELECT table_name FROM information_schema.tables WHERE table_schema = 'public' ORDER BY table_name`;
const primaryKeysRes = await client.query(queryPrimaryKeys);
const tablesRes = await client.query(queryTables);
if (!primaryKeysRes || !tablesRes) assert(false);
const numberOfPrimaryKeys = primaryKeysRes.rows.length;
const numberOfTables = tablesRes.rows.length;
assert(numberOfTables >= 1 && numberOfTables === numberOfPrimaryKeys);
});
OK, thanks, I’ll redesign it.