无法使用db Migrate,rake aborted错误

时间:2017-01-04 01:18:53

标签: ruby-on-rails ruby

我在Codeanywhere工作了一个新项目(我是Ruby的新手),但当我尝试使用def repeat(string, a = 1) a.times.map { string }.join(" ") end 时,我遇到了这个错误:

"rake db : migrate"

在此之前我使用捆绑更新,之后什么也没有,当我放“rake-T”时,db Migartion正在执行任务,当我尝试使用--trace时,传递相同的内容。

我之前尝试使用rake aborted! Don't know how to build task ':' (see --tasks) /home/cabox/.rvm/gems/ruby-2.1.2/gems/rake-12.0.0/exe/rake:27:in `<top (required)>' (See full trace by running task with --trace) 并且同样的事情发生了 `耙子流产!

rake db:migrate

有谁知道如何解决这个问题?

在迁移文件中我有:

SyntaxError:     
/home/cabox/workspace/blog/db/migrate/20170103233409_create_posts.rb:5: syntax error, unexpected ':'                                                                                                                                    
/home/cabox/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `require'                                                                                                                                        
/home/cabox/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `block in require'                                                                                                                               
/home/cabox/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:232:in `load_dependency'                                                                                                                                
/home/cabox/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.6/lib/active_support/dependencies.rb:247:in `require'                                                                                                                                        
/home/cabox/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.6/lib/active_record/migration.rb:761:in `load_migration'                                                                                                                                      
/home/cabox/.rvm/gems/ruby-2.1.2/gems/activerecord- 4.1.6/lib/active_record/migration.rb:757:in `migration'                                                                                                                                           
/home/cabox/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.6/lib/active_record/migration.rb:752:in `disable_ddl_transaction'                                                                                                                             
/home/cabox/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.6/lib/active_record/migration.rb:1044:in `use_transaction?'                                                                                                                                   
/home/cabox/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.6/lib/active_record/migration.rb:1036:in `ddl_transaction'                                                                                                                                    
/home/cabox/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.6/lib/active_record/migration.rb:990:in `execute_migration_in_transaction'                                                                                                                    
/home/cabox/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.6/lib/active_record/migration.rb:952:in `block in migrate'                                                                                                                                    
/home/cabox/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.6/lib/active_record/migration.rb:948:in `each'                                                                                                                                                
/home/cabox/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.6/lib/active_record/migration.rb:948:in `migrate'                                                                                                                                             
/home/cabox/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.6/lib/active_record/migration.rb:807:in `up'                                                                                                                                                  
/home/cabox/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.6/lib/active_record/migration.rb:785:in `migrate'                                                                                                                                             
/home/cabox/.rvm/gems/ruby-2.1.2/gems/activerecord-4.1.6/lib/active_record/railties/databases.rake:34:in `block (2 levels) in <top (required)>'                                                                                                      
/home/cabox/.rvm/gems/ruby-2.1.2/gems/rake-12.0.0/exe/rake:27:in `<top (required)>'                                                                                                                                                                  
Tasks: TOP => db:migrate                                                                                                                                                                                                                             
(See full trace by running task with --trace)` >    

3 个答案:

答案 0 :(得分:5)

我很确定发生了什么,当你输入它时,你正在那里插入一个空格。它必须是

rake db:migrate

rake db : migrate

当运行命令时出现拼写错误或其他类型的输入错误时,该错误消息非常常见。

您的迁移也有拼写错误,应该是

class CreatePosts < ActiveRecord::Migration
  def change
    create_table :posts do |t|
      t.string :title
      t.text :body 
      t.timestamps
    end
  end
end

答案 1 :(得分:1)

Rake是一个软件任务管理工具,与其他系统中的Make等类似

通用语法是

rake namesapce:task

在你的情况下,它是

rake db:migrate

答案 2 :(得分:-1)

如果要再次重建数据库,请尝试执行rake db:reset。它为你做了4件事

rake db:drop
rake db:create
rake db:migrate
rake db:seed