Each foreign key column should have the same name as the column it is referencing

Hello!
I have problem with “Each foreign key column should have the same name as the column it is referencing”.
What to do?

universe=> \d 
                     List of relations
+--------+----------------------+----------+--------------+
| Schema |         Name         |   Type   |    Owner     |
+--------+----------------------+----------+--------------+
| public | alltable             | table    | freecodecamp |
| public | galaxy               | table    | freecodecamp |
| public | galaxy_galaxy_id_seq | sequence | freecodecamp |
| public | moon                 | table    | freecodecamp |
| public | moon_moon_id_seq     | sequence | freecodecamp |
| public | planet               | table    | freecodecamp |
| public | planet_planet_id_seq | sequence | freecodecamp |
| public | star                 | table    | freecodecamp |
| public | star_star_id_seq     | sequence | freecodecamp |
+--------+----------------------+----------+--------------+
(9 rows)

universe=> \d alltable
                        Table "public.alltable"
+-------------+-----------------------+-----------+----------+---------+
|   Column    |         Type          | Collation | Nullable | Default |
+-------------+-----------------------+-----------+----------+---------+
| name        | character varying(30) |           | not null |         |
| alltable_id | character varying(30) |           | not null |         |
| galaxy_id   | integer               |           |          |         |
+-------------+-----------------------+-----------+----------+---------+
Indexes:
    "alltable_pkey" PRIMARY KEY, btree (alltable_id)
    "alltable_alltable_id_key" UNIQUE CONSTRAINT, btree (alltable_id)

universe=> \d galaxy
                                                  Table "public.galaxy"
+----------------------------+-----------------------+-----------+----------+-------------------------------------------+
|           Column           |         Type          | Collation | Nullable |                  Default                  |
+----------------------------+-----------------------+-----------+----------+-------------------------------------------+
| name                       | character varying(30) |           | not null |                                           |
| galaxy_id                  | integer               |           | not null | nextval('galaxy_galaxy_id_seq'::regclass) |
| galaxy_types               | character varying(30) |           | not null |                                           |
| galaxy_size                | integer               |           | not null |                                           |
| galaxy_distance_from_earth | integer               |           |          |                                           |
| alltable_id                | character varying(30) |           |          |                                           |
+----------------------------+-----------------------+-----------+----------+-------------------------------------------+
Indexes:
    "galaxy_pkey" PRIMARY KEY, btree (galaxy_id)
    "galaxy_galaxy_id_key" UNIQUE CONSTRAINT, btree (galaxy_id)
Referenced by:
    TABLE "star" CONSTRAINT "fk" FOREIGN KEY (galaxy_id) REFERENCES galaxy(galaxy_id)

universe=> \d star
                                        Table "public.star"
+-----------+-----------------------+-----------+----------+---------------------------------------+
|  Column   |         Type          | Collation | Nullable |                Default                |
+-----------+-----------------------+-----------+----------+---------------------------------------+
| name      | character varying(30) |           | not null |                                       |
| star_id   | integer               |           | not null | nextval('star_star_id_seq'::regclass) |
| star_size | numeric(6,2)          |           |          |                                       |
| star_type | text                  |           |          |                                       |
| galaxy_id | integer               |           | not null |                                       |
+-----------+-----------------------+-----------+----------+---------------------------------------+
Indexes:
    "star_pkey" PRIMARY KEY, btree (star_id)
    "star_star_id_key" UNIQUE CONSTRAINT, btree (star_id)
Foreign-key constraints:
    "fk" FOREIGN KEY (galaxy_id) REFERENCES galaxy(galaxy_id)
Referenced by:
    TABLE "planet" CONSTRAINT "fk" FOREIGN KEY (star_id) REFERENCES star(star_id)

universe=> \d planet
                                              Table "public.planet"
+---------------------+-----------------------+-----------+----------+-------------------------------------------+
|       Column        |         Type          | Collation | Nullable |                  Default                  |
+---------------------+-----------------------+-----------+----------+-------------------------------------------+
| name                | character varying(30) |           | not null |                                           |
| planet_id           | integer               |           | not null | nextval('planet_planet_id_seq'::regclass) |
| planet_type         | character varying(40) |           |          |                                           |
| planet_has_life     | boolean               |           |          |                                           |
| planet_is_spherical | boolean               |           |          |                                           |
| star_id             | integer               |           | not null |                                           |
+---------------------+-----------------------+-----------+----------+-------------------------------------------+
Indexes:
    "planet_pkey" PRIMARY KEY, btree (planet_id)
    "planet_planet_id_key" UNIQUE CONSTRAINT, btree (planet_id)
Foreign-key constraints:
    "fk" FOREIGN KEY (star_id) REFERENCES star(star_id)
Referenced by:
    TABLE "moon" CONSTRAINT "fk" FOREIGN KEY (planet_id) REFERENCES planet(planet_id)

universe=> \d moon
                                             Table "public.moon"
+---------------------+-----------------------+-----------+----------+---------------------------------------+
|       Column        |         Type          | Collation | Nullable |                Default                |
+---------------------+-----------------------+-----------+----------+---------------------------------------+
| name                | character varying(30) |           | not null |                                       |
| distance_from_earth | integer               |           | not null |                                       |
| moon_id             | integer               |           | not null | nextval('moon_moon_id_seq'::regclass) |
| moon_for_planet     | character varying(50) |           |          |                                       |
| moon_has_life       | boolean               |           |          |                                       |
| planet_id           | integer               |           | not null |                                       |
+---------------------+-----------------------+-----------+----------+---------------------------------------+
Indexes:
    "moon_pkey" PRIMARY KEY, btree (moon_id)
    "moon_moon_id_key" UNIQUE CONSTRAINT, btree (moon_id)
Foreign-key constraints:
    "fk" FOREIGN KEY (planet_id) REFERENCES planet(planet_id)

I don’t see a reason why this particular test is failing, looking at foreign keys.

However, there are some things related to other tests which can cause the issues maybe?

For example - Each primary key should automatically increment

In the alltable - I don’t think primary key is incrementing rn.

When I am experiencing unobvious issues in fcc certs, like the one you shared - I am trying to double-check and resolve other requirements first, sometimes it helps.

Another guess - you have galaxy_id column in both galaxy and alltable tables, but those two are not linked in any way - maybe this fact is messes with the test suite in unexpected way?

I linked the two tables ( galaxy and alltable ) as you suggested, but it didn’t help. Problem still exists. Do you have any more advice?

universe=> \d
                     List of relations
+--------+----------------------+----------+--------------+
| Schema |         Name         |   Type   |    Owner     |
+--------+----------------------+----------+--------------+
| public | alltable             | table    | freecodecamp |
| public | galaxy               | table    | freecodecamp |
| public | galaxy_galaxy_id_seq | sequence | freecodecamp |
| public | moon                 | table    | freecodecamp |
| public | moon_moon_id_seq     | sequence | freecodecamp |
| public | planet               | table    | freecodecamp |
| public | planet_planet_id_seq | sequence | freecodecamp |
| public | star                 | table    | freecodecamp |
| public | star_star_id_seq     | sequence | freecodecamp |
+--------+----------------------+----------+--------------+
(9 rows)

universe=> \d alltable
                        Table "public.alltable"
+-------------+-----------------------+-----------+----------+---------+
|   Column    |         Type          | Collation | Nullable | Default |
+-------------+-----------------------+-----------+----------+---------+
| name        | character varying(30) |           | not null |         |
| alltable_id | character varying(30) |           | not null |         |
| galaxy_id   | integer               |           |          |         |
+-------------+-----------------------+-----------+----------+---------+
Indexes:
    "alltable_pkey" PRIMARY KEY, btree (alltable_id)
    "alltable_alltable_id_key" UNIQUE CONSTRAINT, btree (alltable_id)
Referenced by:
    TABLE "galaxy" CONSTRAINT "fk" FOREIGN KEY (alltable_id) REFERENCES alltable(alltable_id)

universe=> \d galaxy
                                                  Table "public.galaxy"
+----------------------------+-----------------------+-----------+----------+-------------------------------------------+
|           Column           |         Type          | Collation | Nullable |                  Default                  |
+----------------------------+-----------------------+-----------+----------+-------------------------------------------+
| name                       | character varying(30) |           | not null |                                           |
| galaxy_id                  | integer               |           | not null | nextval('galaxy_galaxy_id_seq'::regclass) |
| galaxy_types               | character varying(30) |           | not null |                                           |
| galaxy_size                | integer               |           | not null |                                           |
| galaxy_distance_from_earth | integer               |           |          |                                           |
| alltable_id                | character varying(30) |           |          |                                           |
+----------------------------+-----------------------+-----------+----------+-------------------------------------------+
Indexes:
    "galaxy_pkey" PRIMARY KEY, btree (galaxy_id)
    "galaxy_galaxy_id_key" UNIQUE CONSTRAINT, btree (galaxy_id)
Foreign-key constraints:
    "fk" FOREIGN KEY (alltable_id) REFERENCES alltable(alltable_id)
Referenced by:
    TABLE "star" CONSTRAINT "fk" FOREIGN KEY (galaxy_id) REFERENCES galaxy(galaxy_id)

universe=> \d star
                                        Table "public.star"
+-----------+-----------------------+-----------+----------+---------------------------------------+
|  Column   |         Type          | Collation | Nullable |                Default                |
+-----------+-----------------------+-----------+----------+---------------------------------------+
| name      | character varying(30) |           | not null |                                       |
| star_id   | integer               |           | not null | nextval('star_star_id_seq'::regclass) |
| star_size | numeric(6,2)          |           |          |                                       |
| star_type | text                  |           |          |                                       |
| galaxy_id | integer               |           | not null |                                       |
+-----------+-----------------------+-----------+----------+---------------------------------------+
Indexes:
    "star_pkey" PRIMARY KEY, btree (star_id)
    "star_star_id_key" UNIQUE CONSTRAINT, btree (star_id)
Foreign-key constraints:
    "fk" FOREIGN KEY (galaxy_id) REFERENCES galaxy(galaxy_id)
Referenced by:
    TABLE "planet" CONSTRAINT "fk" FOREIGN KEY (star_id) REFERENCES star(star_id)

universe=> \d planet
                                              Table "public.planet"
+---------------------+-----------------------+-----------+----------+-------------------------------------------+
|       Column        |         Type          | Collation | Nullable |                  Default                  |
+---------------------+-----------------------+-----------+----------+-------------------------------------------+
| name                | character varying(30) |           | not null |                                           |
| planet_id           | integer               |           | not null | nextval('planet_planet_id_seq'::regclass) |
| planet_type         | character varying(40) |           |          |                                           |
| planet_has_life     | boolean               |           |          |                                           |
| planet_is_spherical | boolean               |           |          |                                           |
| star_id             | integer               |           | not null |                                           |
+---------------------+-----------------------+-----------+----------+-------------------------------------------+
Indexes:
    "planet_pkey" PRIMARY KEY, btree (planet_id)
    "planet_planet_id_key" UNIQUE CONSTRAINT, btree (planet_id)
Foreign-key constraints:
    "fk" FOREIGN KEY (star_id) REFERENCES star(star_id)
Referenced by:
    TABLE "moon" CONSTRAINT "fk" FOREIGN KEY (planet_id) REFERENCES planet(planet_id)

universe=> \d star
                                        Table "public.star"
+-----------+-----------------------+-----------+----------+---------------------------------------+
|  Column   |         Type          | Collation | Nullable |                Default                |
+-----------+-----------------------+-----------+----------+---------------------------------------+
| name      | character varying(30) |           | not null |                                       |
| star_id   | integer               |           | not null | nextval('star_star_id_seq'::regclass) |
| star_size | numeric(6,2)          |           |          |                                       |
| star_type | text                  |           |          |                                       |
| galaxy_id | integer               |           | not null |                                       |
+-----------+-----------------------+-----------+----------+---------------------------------------+
Indexes:
    "star_pkey" PRIMARY KEY, btree (star_id)
    "star_star_id_key" UNIQUE CONSTRAINT, btree (star_id)
Foreign-key constraints:
    "fk" FOREIGN KEY (galaxy_id) REFERENCES galaxy(galaxy_id)
Referenced by:
    TABLE "planet" CONSTRAINT "fk" FOREIGN KEY (star_id) REFERENCES star(star_id)