2017-07-28 8 views
0

私はPostGres 9.5でRails 5を使用しています。私は、マイグレーションを実行する際に、次の移行Railsの移行でテーブルにインデックスを追加する適切な方法は何ですか?

class CreateCryptoIndexCurrencies < ActiveRecord::Migration[5.0] 
    def change 
    create_table :crypto_index_currencies do |t| 
     t.references :crypto_currency, foreign_key: true 
     t.date :join_date, :null => false, :default => Time.now 
     t.timestamps 
    end 
    add_index :crypto_index_currencies, :crypto_currency, unique: true 
    end 
end 

は、それがこのエラー

PG::UndefinedColumn: ERROR: column "crypto_currency" does not exist 

インデックスを追加する適切な方法は何で死にかけているのか?私が参照したいテーブル名は "crypto_currencies"と呼ばれます。

答えて

0
add_index 'crypto_index_currencies', ['crypto_currency'], name: "index_crypto_index_currencies_on_crypto_currency", unique: true, using: :btree 

を、それを追加するための構文は次のとおりです:btreeのそのオプション。

0

これは、使用してCREATE_TABLEブロック内

class CreateCryptoIndexCurrencies < ActiveRecord::Migration[5.0] 
    def change 
    create_table :crypto_index_currencies do |t| 
     t.references :crypto_currency, foreign_key: true 
     t.date :join_date, :null => false, :default => Time.now 
     t.index :crypto_currency, unique: true 
    end 
    end 
end 
関連する問題