简体   繁体   English

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

[英]Rails migration file not adding all my defined columns to the db

I'm trying to create a rails app, but somethings going wrong, I'm getting a nasty error undefined method title' for #` 我正在尝试创建一个Rails应用,但是出了点问题,我收到了#`的令人讨厌的错误undefined method title'

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. 我尝试了几种不同的名称,无论出于何种原因,尽管迁移文件中有两列以及时间戳,但在运行rake db:migrate之后,除了时间戳和id之外,只有一个字段。 Not sure why my 'title' field isn't being created :( 不确定为什么未创建我的“标题”字段:(

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM