Rails: Adding an index after adding column

前端 未结 6 764
死守一世寂寞
死守一世寂寞 2020-12-22 22:18

Suppose I created a table table in a Rails app. Some time later, I add a column running:

rails generate migration AddUser_idColumnToTable user_i         


        
6条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-22 22:49

    For those who are using postgresql db and facing error

    StandardError: An error has occurred, this and all later migrations canceled:
    
    === Dangerous operation detected #strong_migrations ===
    
    Adding an index non-concurrently blocks writes
    

    please refer this article

    example:

    class AddAncestryToWasteCodes < ActiveRecord::Migration[6.0]
      disable_ddl_transaction!
    
      def change
        add_column :waste_codes, :ancestry, :string
        add_index :waste_codes, :ancestry, algorithm: :concurrently
      end
    end
    

提交回复
热议问题