Adding a new value to an existing ENUM Type

前端 未结 18 1301
春和景丽
春和景丽 2020-12-04 04:52

I have a table column that uses an enum type. I wish to update that enum type to have an additional possible value. I don\'t want to delete any exi

18条回答
  •  执笔经年
    2020-12-04 05:11

    Complementing @Dariusz 1

    For Rails 4.2.1, there's this doc section:

    == Transactional Migrations

    If the database adapter supports DDL transactions, all migrations will automatically be wrapped in a transaction. There are queries that you can't execute inside a transaction though, and for these situations you can turn the automatic transactions off.

    class ChangeEnum < ActiveRecord::Migration
      disable_ddl_transaction!
    
      def up
        execute "ALTER TYPE model_size ADD VALUE 'new_value'"
      end
    end
    

提交回复
热议问题