Wow! I had a few hairs turn gray on this one. I am using rails 4.2 and trying to run this migration and it was giving me the same error as people above.
PG::UndefinedObject: ERROR: data type character varying has no default
I found out that you can in fact still continue to use schema.rb and do not have to use the config/application.rb
config.active_record.schema_format = :sql
The one major thing I was missing was installing postgres contrib modules. I made the assumption that features like gin and gist were already turned on. I never noticed but modules are shown in your schema.rb file. They appear at the top like this
ActiveRecord::Schema.define(version: 20151203234708) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
enable_extension "pg_trgm"
enable_extension "fuzzystrmatch"
enable_extension "btree_gin"
enable_extension "btree_gist"
if you do not see btree_gin enabled, you can not use the code
add_index :products, :data, using: :gin
you can install any module by running a migration like so. The changes will be reflected in your schema.rb
class InstallSomeContribPackages < ActiveRecord::Migration
def up
execute "CREATE EXTENSION IF NOT EXISTS btree_gin;"
execute "CREATE EXTENSION IF NOT EXISTS btree_gist;"
end
def down
execute "DROP EXTENSION IF EXISTS btree_gin;"
execute "DROP EXTENSION IF EXISTS btree_gist;"
end
end
here is a list of postgres modules