2012-02-20 12 views
1

rake 2プロジェクトで作業中で、rakeタスクの実行中に次のエラーが発生しています。誰かがこれを引き起こしているかもしれないように私を助けることができますか?移行時に次のエラーが発生する

[[email protected] webapp]# rake db:migrate 
(in /root/public/webapp) 
== CreateWhereKeywords: migrating ============================================ 
-- create_table(:where_keywords) 
NOTICE: CREATE TABLE will create implicit sequence "where_keywords_id_seq" for serial column "where_keywords.id" 
NOTICE: CREATE TABLE/PRIMARY KEY will create implicit index "where_keywords_pkey" for table "where_keywords" 
    -> 0.0838s 
-- execute("alter table where_keywords add constraint where_keyword foreign key (where_location_id) references \n  where_locations(id) on delete cascade") 
rake aborted! 
An error has occurred, this and all later migrations canceled: 

PGError: ERROR: foreign key constraint "where_keyword" cannot be implemented 
DETAIL: Key columns "where_location_id" and "id" are of incompatible types: character varying and integer. 
: alter table where_keywords add constraint where_keyword foreign key (where_location_id) references 
     where_locations(id) on delete cascade 
+0

を私達にあなたの移行のコード、および関連するすべてのテーブルのスキーマを表示します。 –

答えて

3

エラーメッセージがかなり明確である:

キー列 "where_location_id" と "ID" が互換性のないタイプがあります。文字が変化し、整数

あなたはwhere_keywords.where_location_idを作成していますFKのwhere_locations.idを参照することができるように、integerにする必要がある場合は、varcharとしてください。もっとこのようにする必要があり

create_table :where_keywords do |t| 
    #... 
    t.string :where_location_id 
    #... 
end 

:あなたの移行は次のようなものがある

create_table :where_keywords do |t| 
    #... 
    t.integer :where_location_id 
    #... 
end 
+0

これは私の問題を解決していただきありがとうございます。私は初心者です、あなたの指導に本当に感謝します –

関連する問題