Update Migration Guide for add_foreign_key
#2202
jvanderen1
started this conversation in
General
Replies: 1 comment 3 replies
-
When you pass an array of columns, Sequel should only attempt to create the foreign key constraint, not add a column: DB.alter_table :projects do
add_foreign_key([:user_id], :users, not_valid: true)
end
# ALTER TABLE "projects" ADD FOREIGN KEY ("user_id") REFERENCES "users" NOT VALID This isn't reversible as you did not name the foreign key constraint. Can you show an example of Sequel creating a column when passing an array of columns? |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
When using
add_foreign_key
in a migration within achange
block and an array with 1 symbol, this does appear to godown
properly. Therefore, updating the migration guide might be helpful for others.Example:
up
: Within the theprojects
, this creates auser_id
column + foreign key constraint pointing to theusers
table (invalid)down
: Within the theprojects
, this drops the foreign key constraint within theuser_id
column pointing to theusers
tableBeta Was this translation helpful? Give feedback.
All reactions