0

これは、私が実行しようとしているときに得られるものですheroku run rake db:migrate

sender_idでしたstring

==  ChangeTypeToInteger: migrating ============================================
-- change_column(:messages, :sender_id, :integer)
rake aborted!
An error has occurred, this and all later migrations canceled:

PG::Error: ERROR:  column "sender_id" cannot be cast automatically to type integer
HINT:  Specify a USING expression to perform the conversion.
: ALTER TABLE "messages" ALTER COLUMN "sender_id" TYPE integer/app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/postgresql_adapter.rb:652:in `exec'
4

1 に答える 1

0

についてALTER TABLEのマニュアルを引用します:

古い型から新しい型への暗黙的なキャストまたは代入キャストがない場合は、USING 句を指定する必要があります。

必要なものは次のとおりです。

ALTER TABLE メッセージ ALTER COLUMN sender_id TYPE 整数

これは、すべてのエントリが に変換可能である限り、データの有無にかかわらず機能integerします。列に を
定義している場合は、それを削除して新しいタイプ用に再作成する必要がある場合があります。DEFAULT

ActiveRecord でこれを行う方法に関するブログ記事を次に示します。

于 2013-09-20T00:18:00.497 に答える