我尝试在 Rails 中创建一个如下所示的数据库迁移:
ruby 脚本/生成脚手架帖子 user_id:int 标题:字符串内容:文本
查看生成的 .rb 文件,果然,我看到了我输入的所有内容:
class CreatePosts < ActiveRecord::Migration
def self.up
create_table :posts do |t|
t.int :user_id # there it is: user_id
t.string :title
t.text :content
t.timestamps
end
end
def self.down
drop_table :posts
end
end
但是在运行rake db:migrate
并检查了我的数据库之后,我发现没有user_id
创建任何列。这里发生了什么?