I want to add a composite primary key into a table. So I added the following raw sql query into my migration file. However, when I run rake db:setup, I did not see a primary key for the table because schema.rb was not affected by this migration. How should I make this work? Thanks.
class AddPrimaryKeyToTable < ActiveRecord::Migration
def up
execute "ALTER TABLE table ADD PRIMARY KEY(identifier,time)"
end
...
答案 0 :(得分:0)
将sql查询更新到下面。
execute "ALTER TABLE table ADD PRIMARY KEY (identifier,time);"