2013-11-15 112 views
0

当我尝试做耙分贝我得到这个错误,当迁移语法错误:迁移:耙分贝:尝试做迁移

rake aborted! 
/Users/farhadam/mboddy/db/migrate/20131113032404_create_microposts.rb:1: syntax error, unexpected tCONSTANT, expecting keyword_do or '{' or '(' 
...t:prepareclass CreateMicroposts < ActiveRecord::Migration 
...        ^
/Users/farhadam/mboddy/db/migrate/20131113032404_create_microposts.rb:10: syntax error, unexpected keyword_end, expecting $end 
/Users/farhadam/.rvm/gems/ruby-1.9.3-p327/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `require' 
/Users/farhadam/.rvm/gems/ruby-1.9.3-p327/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `block in require' 
/Users/farhadam/.rvm/gems/ruby-1.9.3-p327/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:213:in `load_dependency' 
/Users/farhadam/.rvm/gems/ruby-1.9.3-p327/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `require' 
/Users/farhadam/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-4.0.0/lib/active_record/migration.rb:718:in `load_migration' 
/Users/farhadam/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-4.0.0/lib/active_record/migration.rb:714:in `migration' 
/Users/farhadam/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-4.0.0/lib/active_record/migration.rb:708:in `disable_ddl_transaction' 
/Users/farhadam/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-4.0.0/lib/active_record/migration.rb:1012:in `use_transaction?' 
/Users/farhadam/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-4.0.0/lib/active_record/migration.rb:1004:in `ddl_transaction' 
/Users/farhadam/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-4.0.0/lib/active_record/migration.rb:958:in `execute_migration_in_transaction' 
/Users/farhadam/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-4.0.0/lib/active_record/migration.rb:920:in `block in migrate' 
/Users/farhadam/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-4.0.0/lib/active_record/migration.rb:916:in `each' 
/Users/farhadam/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-4.0.0/lib/active_record/migration.rb:916:in `migrate' 
/Users/farhadam/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-4.0.0/lib/active_record/migration.rb:764:in `up' 
/Users/farhadam/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-4.0.0/lib/active_record/migration.rb:742:in `migrate' 
/Users/farhadam/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-4.0.0/lib/active_record/railties/databases.rake:42:in `block (2 levels) in <top (required)>' 
/Users/farhadam/.rvm/gems/ruby-1.9.3-p327/bin/ruby_noexec_wrapper:14:in `eval' 
/Users/farhadam/.rvm/gems/ruby-1.9.3-p327/bin/ruby_noexec_wrapper:14:in `<main>' 
Tasks: TOP => db:migrate 
(See full trace by running task with --trace) 

这里是我的迁移表:

bundle exec rake test:prepare 
class CreateMicroposts < ActiveRecord::Migration 
    def change 
    create_table :microposts do |t| 
     t.string :content 
     t.integer :user_id 
     t.timestamps 
    end 
    add_index :microposts,[:user_id,:created_at] 
    end 
end 

有谁知道为什么会发生这种情况,以及我如何解决这个问题,以便在迁移时不会给我这个错误?

+0

任何这运气了吗? – zeantsoi

回答

1

从迁移文件开始删除这一切:bundle exec rake test:prepare

bundle exec rake test:prepare从命令行中运行。细分,bundle exec在当前包的上下文中执行脚本; rake test:prepare(或更可能是rake db:test:prepare)是要执行的rake任务。

您应该迁移内容如下:

class CreateMicroposts < ActiveRecord::Migration 
    def change 
     create_table :microposts do |t| 
      t.string :content 
      t.integer :user_id 
      t.timestamps 
     end 
     add_index :microposts,[:user_id,:created_at] 
    end 
end 
+1

谢谢!我是红宝石noob,这工作:) – Farhadam

1

bundle exec rake test:prepare不是Ruby--它不应该在您的迁移文件中。