假设我创建了此表:
class CreateTweets < ActiveRecord::Migration
def up
create_table :contents do |t|
t.string :user_id
t.string :content
t.timestamps
end
end
def down
drop_table :contents
end
end
如何通过终端更改用户id的值,以用于我拥有id的特定内容,并将其保存以用于测试目的。
非常感谢。
最佳答案
要将ID为1的内容更新为用户ID为5(假设用户ID为整数字段):
运行rails console
,然后Content.update(1, user_id: 5)