1

I'm trying to temporarily remove the uniqueness constraint on emails in my app. In my schema, the users table currently contains this following line - I'd like to change the true at the end:

t.index ["email"], name: "index_users_on_email", unique: true

I'm very unsure about which migration/syntax I need to run in order for the last part to be false. Is it: rails g migration change_column :users, :index_users_on_email, :index, unique: false? or is there a better way?

Any help would be appreciated! I'm scared of messing things up in the db - still a beginner

strivedi183
  • 4,749
  • 2
  • 31
  • 38
Brednad
  • 45
  • 5
  • 1
    Does this answer your question? [How can I remove a unique constraint from a database column in Rails?](https://stackoverflow.com/questions/33495396/how-can-i-remove-a-unique-constraint-from-a-database-column-in-rails) – rmlockerd Aug 02 '21 at 21:24

1 Answers1

0

I would suggestion just removing the index and then adding one without an uniqueness constraint. After you are done doing what you need to do and want to re-add it, you can drop the index without the uniqueness constraint and re-add one with out

# first migration
remove_index :users, column: :index, unique: true
add_index :users, :index

And whenever you want to add it back

# second migration
remove_index :users, column: :index
add_index :users, :index, unique: true
Dharman
  • 30,962
  • 25
  • 85
  • 135
strivedi183
  • 4,749
  • 2
  • 31
  • 38