NOT able to rake db:migrate

半世苍凉 提交于 2020-01-26 04:39:11

问题


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)

回答1:


You called:

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

remove the excess \:

\Users\MEGHA\sagar_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).




回答2:


You probably used text instead of :text in your migration.



来源:https://stackoverflow.com/questions/22806780/not-able-to-rake-dbmigrate

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!