I am using gender field of my user table as enum type.
Migration also runs sucessfully. But the schema.rb get crashes.
After running the migration, my schema.rb looks:
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
my migration is:
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
I don't understand why the schema.rb crashes. 
Postgres custom types aren't supported by "Ruby-style" schemas. In order to use this functionality, you'll need to switch to a SQL-formatted schema. Switch the value of config.active_record.schema_format in config/application.rb to :sql.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With