我有这个表:更改列名的Rails
class CreateShoes < ActiveRecord::Migration
def change
create_table :shoes do |t|
t.string :name
t.boolean :leather
t.integer :season
t.timestamps null: false
end
end
end
的 '季节' 一栏被称为 'season_id'。我知道我必须编写't.rename:season,:season_id',如http://edgeguides.rubyonrails.org/active_record_migrations.html#column-modifiers中所解释的,但我无法找到正确的语法。它应该是?
class CreateShoes < ActiveRecord::Migration
def change
create_table :shoes do |t|
t.string :name
t.boolean :leather
t.integer :season
t.timestamps null: false
end
change_table :products do |t|
t.rename :season, :season_id
end
end
end
不起作用。我需要在Mac控制台中做什么?谢谢!
你为什么要在同一迁移中重命名它?回滚并将其修复到'create_table'中,或者创建一个新的迁移。你也可以直接写'rename_column:shoes,season,season_id',而不是把它放在一个块中。 –
我不知道我在做什么。学习:)忘了补充表中有数据。创造新的迁移意味着新的“变化”? thx – Pere
这意味着有一个新的迁移,它有自己的'change'方法。 –