首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >postgres中枚举类型的schema.rb崩溃

postgres中枚举类型的schema.rb崩溃
EN

Stack Overflow用户
提问于 2018-07-23 20:12:53
回答 1查看 1.5K关注 0票数 5

我使用user表的gender字段作为enum类型。

迁移也运行得很成功。但是schema.rb会崩溃。

运行迁移后,我的schema.rb如下所示:

代码语言:javascript
复制
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

我的迁移是:

代码语言:javascript
复制
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会崩溃。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-07-23 21:18:24

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

票数 12
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51478522

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档