Created
January 19, 2021 07:08
-
-
Save poudelmadhav/7496cf55b059a081cf6ac7736f97f2bb to your computer and use it in GitHub Desktop.
Add unique constrainst on existing foreign_key constrant in rails migration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Example: | |
# Adding unique index on user_id(existing foreign_key) of kycs table | |
class AddUniqueIndexOnUserIdToKycs < ActiveRecord::Migration[6.0] | |
def change | |
remove_foreign_key :kycs, :users | |
remove_index :kycs, :user_id | |
add_index :kycs, :user_id, unique: true | |
add_foreign_key :kycs, :users | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment