我正在使用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

我的迁移是:
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崩溃。

最佳答案

“Ruby样式”模式不支持Postgres自定义类型。为了使用此功能,您需要切换到SQL格式的架构。将config.active_record.schema_format中的config/application.rb的值切换为:sql

关于ruby-on-rails - postgres中的枚举类型的schema.rb崩溃,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51478522/

10-12 16:41
查看更多