无法进行db:migrate

时间:2014-04-02 09:17:57

标签: ruby rake

C:\Users\MEGHA>rails new sagar_blog
      create
      create  README.rdoc
      create  Rakefile
      ... <snip> ...
Using turbolinks (2.2.1)
Using uglifier (2.5.0)
Your bundle is complete!
Use `bundle show [gemname]` to see where a bundled gem is installed.

C:\Users\MEGHA>cd sagar_blog

C:\Users\MEGHA\sagar_blog>rails generate scaffold post title:string \ body:text
      invoke  active_record
      ... <snip> ...
      create      app/assets/stylesheets/posts.css.scss
      invoke  scss
      create    app/assets/stylesheets/scaffolds.css.scss

C:\Users\MEGHA\sagar_blog>rails generate scaffold comment post_id:integer  body:
text
      invoke  active_record
      create    db/migrate/20140402091132_create_comments.rb
      ... <snip> ...
      invoke  scss
   identical    app/assets/stylesheets/scaffolds.css.scss

C:\Users\MEGHA\sagar_blog>rake db:migrate
== 20140402091036 CreatePosts: migrating ======================================
-- create_table(:posts)
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:

undefined method `text' for :t:SymbolC:/Users/MEGHA/sagar_blog/db/migrate/201404
02091036_create_posts.rb:6:in `block in change'
C:/Users/MEGHA/sagar_blog/db/migrate/20140402091036_create_posts.rb:3:in `change
'
C:in `migrate'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)

2 个答案:

答案 0 :(得分:2)

您致电:

  

\ Users \ MEGHA \ sagar_blog&gt; rails生成脚手架帖子标题:string \ body:text

删除多余的\

\Users\MEGHA\sagar_blog>rails generate scaffold post title:string body:text

\实际上是一个空白,这会导致body字段被调用body(名称前面有一个空格),这会导致迁移文件生成一行{ {1}}而不是迁移失败的t.text : body(可能稍后也会失败其他内容)。

答案 1 :(得分:0)

您可能在迁移过程中使用了text而不是:text