class CreateBallots < ActiveRecord::Migration
def change
create_table :ballots do |t|
t.references :user
t.references :score
t.references :election
t.string :key
t.timestamps
end
add_index :ballots, :user
add_index :ballots, :score
add_index :ballots, :election
end
end
wyniki:szyn: "t.references" nie działa podczas tworzenia indeksu
SQLite3::SQLException: table ballots has no column named user: CREATE INDEX "index_ballots_on_user" ON "ballots" ("user")/home/muhd/awesomevote/db/migrate/20130624024349_create_ballots.rb:10:in `change'
Myślałem t.references
miała obsługiwać to dla mnie?
Ach, w porządku. Sądziłem, że ta sama składnia będzie używana między t.references i add_index, ale myślę, że tak nie jest. Dzięki za podpowiedź za zrobienie 'index: true'; Nie wiedziałem o tym. – Muhd
Tak, to nie jest tak oczywiste, ale "t.references" odwołuje się do "użytkownika", dodając kolumnę "user_id" :) –