How do I describe an enumeration column in a Rails 3 migration?

前端 未结 11 1626
误落风尘
误落风尘 2020-12-24 04:23

How do I describe an enumeration column in a Rails 3 migration?

11条回答
  •  臣服心动
    2020-12-24 05:25

    You can describe an enumeration column with:

    t.column 'role', 'user_role'
    

    I created the enum type with:

    execute "CREATE TYPE user_role AS ENUM ('consultant', 'admin');"
    

    Inspecting the database:

        Column     |          Type          | Modifiers | Storage  | Stats target | Description
    ---------------+------------------------+-----------+----------+--------------+-------------
     role          | user_role              |           | plain    |              |
    

提交回复
热议问题