Rails 迁移文件未将我定义的所有列添加到数据库中

发布于 2024-08-08 04:51:35 字数 568 浏览 2 评论 0原文

我正在尝试创建一个 Rails 应用程序,但出了点问题,我收到了一个令人讨厌的错误 undefined methodtitle' 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 methodtitle' 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

诗酒趁年少 2024-08-15 04:51:35

字符串不应该是小写的“S”吗?

Shouldn't string be a lowercase 'S'?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文