Hstore에서 Array로 변경할 열이 내 Rails/Postgres 앱에 있습니다. 그러나, 나는 그렇게 할 때HStore 열을 배열로 변경
class ChangePhonesToArray < ActiveRecord::Migration
def up
new_phones = {}
Place.find_each do |p|
new_phones[p.id] = p.phones.values.map{ |v| v.gsub(%r!\D!, '') } # get rid of non-number characters while I'm at it
end
remove_column :places, :phones
add_column :places, :phones, :string, array: true, default: []
new_phones.each do |k, v|
p = Place.find(k)
p.update_attributes!(phones: v)
end
end
...
end
: (나는 해시로 전화를 저장했다, 그래서 나는 {default: 123, mobile: 1234}
을 할 수 있지만,이/필요한 유용하지라고 판단했습니다)
phones
은 여전히 Hstore 열임을 알리는이 불쾌한 DB 오류가 발생합니다!
StandardError: An error has occurred, this and all later migrations canceled:
can't cast Array to hstore/Users/sasha/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/quoting.rb:76:in `type_cast'
/Users/sasha/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.4/lib/active_record/connection_adapters/postgresql/quoting.rb:111:in `type_cast'
/Users/sasha/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.4/lib/active_record/connection_adapters/postgresql_adapter.rb:828:in `block in exec_cache'
/Users/sasha/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.4/lib/active_record/connection_adapters/postgresql_adapter.rb:827:in `map'
/Users/sasha/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.4/lib/active_record/connection_adapters/postgresql_adapter.rb:827:in `exec_cache'
/Users/sasha/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.4/lib/active_record/connection_adapters/postgresql/database_statements.rb:155:in `exec_delete'
/Users/sasha/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/database_statements.rb:101:in `update'
/Users/sasha/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract/query_cache.rb:14:in `update'
I의 열이 제대로 제거되지 않고, 그래서 바로 제 뒤에 존재하는 제 2 remove_column
을 던지고, 그 컬럼이 이미 제거 된 것을 시사 오류 아래 던져 가정! (그러나 명백하게 완전하게).
StandardError: An error has occurred, this and all later migrations canceled:
PG::UndefinedColumn: ERROR: column "phones" of relation "places" does not exist
: ALTER TABLE "places" DROP "phones"/Users/sasha/.rvm/gems/ruby-2.1.2/gems/rack-mini-profiler-0.9.2/lib/patches/sql_patches.rb:160:in `exec'
/Users/sasha/.rvm/gems/ruby-2.1.2/gems/rack-mini-profiler-0.9.2/lib/patches/sql_patches.rb:160:in `async_exec'
/Users/sasha/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.4/lib/active_record/connection_adapters/postgresql/database_statements.rb:128:in `block in execute'
/Users/sasha/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract_adapter.rb:373:in `block in log'
/Users/sasha/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/Users/sasha/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.4/lib/active_record/connection_adapters/abstract_adapter.rb:367:in `log'
/Users/sasha/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.4/lib/active_record/connection_adapters/postgresql/database_statements.rb:127:in `execute'
여기에 무슨 일이 벌어지고 있는지, 어떻게 해결할 수 있습니까?
고맙습니다! 정보를 재설정해야하는 클래스 자체에 대해서는 전혀 몰랐습니다. 차가워서 배우십시오. 매력처럼 일했습니다. – Sasha