0

rake db:migrate: を実行しようとすると、このエラーが発生します。

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

なぜこれが起こっているのか、移行を行ったときにこのエラーが発生しないように修正する方法を知っている人はいますか?

4

2 に答える 2

1

bundle exec rake test:prepareは Ruby ではありません - 移行ファイルに含めるべきではありません。

于 2013-11-15T01:09:43.613 に答える
0

移行ファイルの先頭から次のすべてを削除します。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
于 2013-11-15T01:09:55.017 に答える