Hi,
Although I have tried multiple times trying to add a foreign key to the table(star) with the command:
ALTER TABLE star ADD FOREIGN KEY (galaxy_id) REFERENCES galaxy(galaxy_id);
The test does not anyhow return a passed result.
Here is what the system displayed when I press ‘run’:
SUBTASKS 1.1 :10 Each “star” row should have a foreign key that references one of the “galaxy” rows
What is the solution to this? Ty
The error you’re encountering is likely due to one or more of the existing “star” rows having a galaxy_id value that doesn’t match any of the existing galaxy_id values in the “galaxy” table.
Before adding a foreign key constraint to the “star” table, you need to ensure that there are no existing rows in the “star” table with invalid galaxy_id values. You can do this by either:
- Deleting the “star” rows with invalid
galaxy_idvalues, or - Updating the “star” rows with invalid
galaxy_idvalues to have a validgalaxy_idthat matches one of the values in the “galaxy” table.
Once you have fixed the data, you should be able to add the foreign key constraint to the “star” table using the ALTER TABLE statement you posted in your question.
1 Like
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.