P
Prisma•13mo ago
mhamid3d

Check constraint migration fails with syntax error

I made the following migration file and ran the migration:
ALTER TABLE "api_owner"
ADD CONSTRAINT "check_owner_one_null" CHECK (user_id IS NOT NULL AND organization_id IS NULL) OR (user_id IS NULL AND organization_id IS NOT NULL);

ALTER TABLE "api_entity"
ADD CONSTRAINT "check_non_self_parent" CHECK (parent_id <> id);
ALTER TABLE "api_owner"
ADD CONSTRAINT "check_owner_one_null" CHECK (user_id IS NOT NULL AND organization_id IS NULL) OR (user_id IS NULL AND organization_id IS NOT NULL);

ALTER TABLE "api_entity"
ADD CONSTRAINT "check_non_self_parent" CHECK (parent_id <> id);
And it results in this error:
Migration `20240404221624_check_constraints` failed to apply cleanly to the shadow database.
Error:
ERROR: syntax error at or near "OR"
0: sql_schema_connector::validate_migrations
with namespaces=None
at schema-engine\connectors\sql-schema-connector\src\lib.rs:324
1: schema_core::state::DevDiagnostic
at schema-engine\core\src\state.rs:267
Migration `20240404221624_check_constraints` failed to apply cleanly to the shadow database.
Error:
ERROR: syntax error at or near "OR"
0: sql_schema_connector::validate_migrations
with namespaces=None
at schema-engine\connectors\sql-schema-connector\src\lib.rs:324
1: schema_core::state::DevDiagnostic
at schema-engine\core\src\state.rs:267
1 Reply
RaphaelEtim
RaphaelEtim•13mo ago
Hi @mhamid3d 👋 Which database are you using? Can you share the schema file so i can reproduce?

Did you find this page helpful?