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 VALIDThis 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_keyin a migration within achangeblock and an array with 1 symbol, this does appear to godownproperly. Therefore, updating the migration guide might be helpful for others.Example:
up: Within the theprojects, this creates auser_idcolumn + foreign key constraint pointing to theuserstable (invalid)down: Within the theprojects, this drops the foreign key constraint within theuser_idcolumn pointing to theuserstableBeta Was this translation helpful? Give feedback.
All reactions