'How to Add Foreign Key with Extra Information in MySQL

I have 2 tables departments and locations and locationID is the primary key in locations table and departments table also has that field.

Now after adding a data with locationID 101 in the departments table it won't let me add foreign key referencing locations table because the locations table doesn't have any data with locationID 101 so the data with locationID 101 is extra in the departments table that doesn't belong in locations table.

So how do I fix that without deleting the information from departments table or adding the info in locations table (if possible)?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source