Skip to main content

What this error means

FOREIGN_KEYS_REFERENCED_VIEW means a foreign key references a view. A common underlying message is:

Why PlanetScale rejects it

MySQL foreign key constraints must reference real base tables. A view is a stored query, not a table that can enforce referential integrity.

How to fix it

Reference the underlying table instead of the view, or remove the foreign key constraint and enforce the relationship in application code. Invalid:
Valid table reference:

Need help?

Get help from the PlanetScale Support team, or join our Discord community to see how others are using PlanetScale.