3
ALTER TABLE <table name> WITH NOCHECK
    ADD CONSTRAINT attachments_user_id_fkey FOREIGN KEY (user_id)
    REFERENCES public.users (id) MATCH SIMPLE
    ON UPDATE NO ACTION
    ON DELETE NO ACTION;

The above query is throwing the following error ERROR: syntax error at or near "WITH NOCHECK"

1

1 Answer 1

5

That appears to be SQL Server syntax. PostgreSQL doesn't support that WITH NOCHECK, I think you want:

ALTER TABLE <table name>
ADD CONSTRAINT attachments_user_id_fkey FOREIGN KEY (user_id)
REFERENCES public.users (id) NOT VALID

You'll have to check the documentation to see if there are equivalents for the rest of the options you're trying to use.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.