我使用user表的gender字段作为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我的迁移是:
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我不明白为什么schema.rb会崩溃。
发布于 2018-07-23 21:18:24
“Ruby样式”模式不支持Postgres自定义类型。为了使用此功能,您需要切换到SQL格式的模式。将config/application.rb中的config.active_record.schema_format值切换为:sql。
https://stackoverflow.com/questions/51478522
复制相似问题