Skip to main content

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_DISALLOWED means the schema contains a FOREIGN KEY constraint, but the database is not configured to allow foreign key constraints. A common error message is:
table "posts" has a foreign key constraint: foreign key constraints are not supported.
The error may also include the local column names used by the foreign key.

Why PlanetScale rejects it

PlanetScale databases can run with foreign key constraints disabled or managed. When constraints are disabled, Vitess rejects DDL that creates them so the database does not enter a mixed or unsupported foreign key mode.

How to fix it

Choose one of these approaches:
  • Enable foreign key constraint support for the database if your workload needs database-enforced referential integrity and the database meets the prerequisites.
  • Remove the CONSTRAINT ... FOREIGN KEY clause and keep ordinary indexes for query performance.
  • Enforce referential integrity in application code or background jobs instead of with database constraints.
Invalid when foreign keys are disabled:
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)
);
Constraint-free version:
CREATE TABLE posts (
  id bigint unsigned NOT NULL,
  author_id bigint unsigned NOT NULL,
  PRIMARY KEY (id),
  KEY posts_author_idx (author_id)
);

Need help?

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