Documentation Index
Fetch the complete documentation index at: https://planetscale.com/docs/llms.txt
Use this file to discover all available pages before exploring further.
What this error means
FOREIGN_KEYS_REFERENCED_VIEW means a foreign key references a view.
A common underlying message is:
table `posts` foreign key references view `active_users`
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:
CREATE VIEW active_users AS
SELECT id FROM users WHERE active = 1;
CREATE TABLE posts (
id bigint unsigned NOT NULL,
author_id bigint unsigned NOT NULL,
PRIMARY KEY (id),
CONSTRAINT posts_author_fk FOREIGN KEY (author_id) REFERENCES active_users(id)
);
Valid table reference:
CREATE TABLE posts (
id bigint unsigned NOT NULL,
author_id bigint unsigned NOT NULL,
PRIMARY KEY (id),
CONSTRAINT posts_author_fk FOREIGN KEY (author_id) REFERENCES users(id)
);
Need help?
Get help from the PlanetScale Support team, or join our Discord community to see how others are using PlanetScale.