patternsqlMajor
postgresql rename a foreignkey after renaming a table
Viewed 0 times
postgresqlforeignkeyafterrenamingtablerename
Problem
I renamed a table, and apparently a foreignkey in it doesn't get changed, and causing problems,
Although when I
Which the only relation to
Anyway - I have no problem deleting the foreignkey and recreating it, but I can't figure out how to do it
Although when I
\d error I get:"error_test_id_fkey" FOREIGN KEY (test_id) REFERENCES test(id) ON DELETE CASCADEWhich the only relation to
error name, is the name (weird)Anyway - I have no problem deleting the foreignkey and recreating it, but I can't figure out how to do it
Solution
If you are using PostgreSQL 9.2 or newer, you can use
RENAME CONSTRAINT:ALTER TABLE name RENAME CONSTRAINT "error_test_id_fkey" TO "the_new_name_fkey";Code Snippets
ALTER TABLE name RENAME CONSTRAINT "error_test_id_fkey" TO "the_new_name_fkey";Context
StackExchange Database Administrators Q#98875, answer score: 39
Revisions (0)
No revisions yet.