Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
176 views
in Technique[技术] by (71.8m points)

ruby - NOT able to rake db:migrate

C:UsersMEGHA>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:UsersMEGHA>cd sagar_blog

C:UsersMEGHAsagar_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:UsersMEGHAsagar_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:UsersMEGHAsagar_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)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You called:

UsersMEGHAsagar_blog>rails generate scaffold post title:string body:text

remove the excess :

UsersMEGHAsagar_blog>rails generate scaffold post title:string body:text

is actually a hard blank, which causes the body field to be called body (with a blank before the name), this causes the migration file to generate a line t.text : body instead of t.text :body, which fails the migration (and probably later will fail other stuff as well).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...