Sou*_*nka 1 postgresql enums ruby-on-rails
我正在使用表格的gender字段user作为enum类型。
迁移也成功进行。但是schema.rb崩溃了。
运行迁移后,我的schema.rb样子:
ActiveRecord::Schema.define(version: 2018_07_23_115046) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
# Could not dump table "users" because of following StandardError
# Unknown type 'gender' for column 'gender'
end
Run Code Online (Sandbox Code Playgroud)
我的迁移是:
class AddGenderToUsers < ActiveRecord::Migration[5.2]
def up
execute <<-SQL
CREATE TYPE gender AS ENUM ('male', 'female', 'not_sure', 'prefer_not_to_disclose');
SQL
add_column :users, :gender, :gender, index: true
end
def down
remove_column :users, :gender
execute <<-SQL
DROP TYPE gender;
SQL
end
end
Run Code Online (Sandbox Code Playgroud)
我不明白为什么会schema.rb崩溃。
“ Ruby样式”模式不支持Postgres自定义类型。为了使用此功能,您需要切换到SQL格式的架构。将config.active_record.schema_formatin 的值切换config/application.rb为:sql。
| 归档时间: |
|
| 查看次数: |
588 次 |
| 最近记录: |