Rails 迁移文件未将我定义的所有列添加到数据库中
我正在尝试创建一个 Rails 应用程序,但出了点问题,我收到了一个令人讨厌的错误 undefined method
title' for #`
我使用了这个 ling:
ruby script/generate scaffold Blog title:String body:text
来生成以下迁移文件:
class CreateBlogs < ActiveRecord::Migration
def self.up
create_table :blogs do |t|
t.String :title
t.text :body
t.timestamps
end
end
def self.down
drop_table :blogs
end
end
检查数据库后发现没有“标题”列。我尝试过使用几个不同的名称,无论出于何种原因,即使迁移文件中有两列以及时间戳,在我运行 rake db:migrate 后,除了时间戳和 id 之外,只有一个字段。不知道为什么我的“标题”字段没有被创建:(
I'm trying to create a rails app, but somethings going wrong, I'm getting a nasty error undefined method
title' for #`
I've used this ling:
ruby script/generate scaffold Blog title:String body:text
to generate the following migration file:
class CreateBlogs < ActiveRecord::Migration
def self.up
create_table :blogs do |t|
t.String :title
t.text :body
t.timestamps
end
end
def self.down
drop_table :blogs
end
end
Upon inspection of the database, there's no 'title' column. I've tried this with a few different names and for whatever reason, even though there's two columns along with the timestamps in the migration file, after I've run rake db:migrate there's only one field in addition to the timestamps and id. Not sure why my 'title' field isn't being created :(
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
字符串不应该是小写的“S”吗?
Shouldn't string be a lowercase 'S'?