Say I have the following tables:
User (
ID INT NOT NULL PRIMARY KEY
, providerID INT
)
ProviderPlan(
planID INT NOT NULL PRIMARY KEY
, providerID INT NOT NULL
)
Then I want to make a foreign key mapping the two tables:
ALTER TABLE ProviderPlan ADD FOREIGN KEY (providerID) REFERENCES User(providerID) ON DELETE CASCADE;
When I try this, I get the following error:
Error Code: 1215. Cannot add foreign key constraint
My best guess for the error is because one column is nullable while the other is not. If this is the case, how can I setup a nullable column in a reference table as a not null foreign key in another table?