0
我正在使用Rails 5和PostGres 9.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」。