AWS Cloud9で「StandardError: An error has occurred, this and all later migrations canceled:」と表示された場合の対処

AWS Cloud9で「StandardError: An error has occurred, this and all later migrations canceled:」と表示された場合の対処について書きます。

Cloud9でRuby on Railsプロジェクト作成。プロジェクトの「db」、「migrate」フォルダの中の「20200709004220_create_tasks.rb」というファイルは、下記のコードが記述されている状態。

class CreateTasks < ActiveRecord::Migration[5.1]
def change
create_table :tasks do |t|
t.string :title
t.boolean :done, default: fales

t.timestamps
end
end
end

この状態で、db:migrateコマンドを用いて、マイグレーションファイルを元にデータベースの中にあるテーブル操作を行います。

ec2-user:~/environment/rails_projects/todo (master) $ rake db:migrate

== 20200709004220 CreateTasks: migrating ======================================

— create_table(:tasks)

— fales()

rake aborted!

StandardError: An error has occurred, this and all later migrations canceled:

 

undefined local variable or method `fales’ for #<CreateTasks:0x00000000041a5488>

Did you mean?  false

/home/ec2-user/.rvm/gems/ruby-2.6.3/gems/activerecord-5.1.7/lib/active_record/migration.rb:848:in `block in method_missing’

/home/ec2-user/.rvm/gems/ruby-2.6.3/gems/activerecord-5.1.7/lib/active_record/migration.rb:818:in `block in say_with_time’

/home/ec2-user/.rvm/gems/ruby-2.6.3/gems/activerecord-5.1.7/lib/active_record/migration.rb:818:in `say_with_time’

/home/ec2-user/.rvm/gems/ruby-2.6.3/gems/activerecord-5.1.7/lib/active_record/migration.rb:838:in `method_missing’

/home/ec2-user/environment/rails_projects/todo/db/migrate/20200709004220_create_tasks.rb:5:in `block in change’

/home/ec2-user/.rvm/gems/ruby-2.6.3/gems/activerecord-5.1.7/lib/active_record/connection_adapters/abstract/schema_statements.rb:282:in `create_table’

/home/ec2-user/.rvm/gems/ruby-2.6.3/gems/activerecord-5.1.7/lib/active_record/migration.rb:849:in `block in method_missing’

/home/ec2-user/.rvm/gems/ruby-2.6.3/gems/activerecord-5.1.7/lib/active_record/migration.rb:818:in `block in say_with_time’

/home/ec2-user/.rvm/gems/ruby-2.6.3/gems/activerecord-5.1.7/lib/active_record/migration.rb:818:in `say_with_time’

/home/ec2-user/.rvm/gems/ruby-2.6.3/gems/activerecord-5.1.7/lib/active_record/migration.rb:838:in `method_missing’

/home/ec2-user/environment/rails_projects/todo/db/migrate/20200709004220_create_tasks.rb:3:in `change’

/home/ec2-user/.rvm/gems/ruby-2.6.3/gems/activerecord-5.1.7/lib/active_record/migration.rb:792:in `exec_migration’

/home/ec2-user/.rvm/gems/ruby-2.6.3/gems/activerecord-5.1.7/lib/active_record/migration.rb:776:in `block (2 levels) in migrate’

/home/ec2-user/.rvm/gems/ruby-2.6.3/gems/activerecord-5.1.7/lib/active_record/migration.rb:775:in `block in migrate’

/home/ec2-user/.rvm/gems/ruby-2.6.3/gems/activerecord-5.1.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:410:in `with_connection’

/home/ec2-user/.rvm/gems/ruby-2.6.3/gems/activerecord-5.1.7/lib/active_record/migration.rb:774:in `migrate’

/home/ec2-user/.rvm/gems/ruby-2.6.3/gems/activerecord-5.1.7/lib/active_record/migration.rb:953:in `migrate’

/home/ec2-user/.rvm/gems/ruby-2.6.3/gems/activerecord-5.1.7/lib/active_record/migration.rb:1230:in `block in execute_migration_in_transaction’

/home/ec2-user/.rvm/gems/ruby-2.6.3/gems/activerecord-5.1.7/lib/active_record/migration.rb:1298:in `block in ddl_transaction’

/home/ec2-user/.rvm/gems/ruby-2.6.3/gems/activerecord-5.1.7/lib/active_record/connection_adapters/abstract/database_statements.rb:235:in `block in transaction’

/home/ec2-user/.rvm/gems/ruby-2.6.3/gems/activerecord-5.1.7/lib/active_record/connection_adapters/abstract/transaction.rb:194:in `block in within_new_transaction’

/home/ec2-user/.rvm/gems/ruby-2.6.3/gems/activerecord-5.1.7/lib/active_record/connection_adapters/abstract/transaction.rb:191:in `within_new_transaction’

/home/ec2-user/.rvm/gems/ruby-2.6.3/gems/activerecord-5.1.7/lib/active_record/connection_adapters/abstract/database_statements.rb:235:in `transaction’

/home/ec2-user/.rvm/gems/ruby-2.6.3/gems/activerecord-5.1.7/lib/active_record/transactions.rb:210:in `transaction’

/home/ec2-user/.rvm/gems/ruby-2.6.3/gems/activerecord-5.1.7/lib/active_record/migration.rb:1298:in `ddl_transaction’

/home/ec2-user/.rvm/gems/ruby-2.6.3/gems/activerecord-5.1.7/lib/active_record/migration.rb:1229:in `execute_migration_in_transaction’

/home/ec2-user/.rvm/gems/ruby-2.6.3/gems/activerecord-5.1.7/lib/active_record/migration.rb:1201:in `block in migrate_without_lock’

/home/ec2-user/.rvm/gems/ruby-2.6.3/gems/activerecord-5.1.7/lib/active_record/migration.rb:1200:in `each’

/home/ec2-user/.rvm/gems/ruby-2.6.3/gems/activerecord-5.1.7/lib/active_record/migration.rb:1200:in `migrate_without_lock’

/home/ec2-user/.rvm/gems/ruby-2.6.3/gems/activerecord-5.1.7/lib/active_record/migration.rb:1150:in `migrate’

/home/ec2-user/.rvm/gems/ruby-2.6.3/gems/activerecord-5.1.7/lib/active_record/migration.rb:1007:in `up’

/home/ec2-user/.rvm/gems/ruby-2.6.3/gems/activerecord-5.1.7/lib/active_record/migration.rb:985:in `migrate’

/home/ec2-user/.rvm/gems/ruby-2.6.3/gems/activerecord-5.1.7/lib/active_record/tasks/database_tasks.rb:171:in `migrate’

/home/ec2-user/.rvm/gems/ruby-2.6.3/gems/activerecord-5.1.7/lib/active_record/railties/databases.rake:58:in `block (2 levels) in <top (required)>’

/home/ec2-user/.rvm/gems/ruby-2.6.3/gems/rake-13.0.1/exe/rake:27:in `<top (required)>’

/home/ec2-user/.rvm/gems/ruby-2.6.3/bin/ruby_executable_hooks:24:in `eval’

/home/ec2-user/.rvm/gems/ruby-2.6.3/bin/ruby_executable_hooks:24:in `<main>’

 

Caused by:

NameError: undefined local variable or method `fales’ for #<CreateTasks:0x00000000041a5488>

Did you mean?  false

/home/ec2-user/.rvm/gems/ruby-2.6.3/gems/activerecord-5.1.7/lib/active_record/migration.rb:848:in `block in method_missing’

/home/ec2-user/.rvm/gems/ruby-2.6.3/gems/activerecord-5.1.7/lib/active_record/migration.rb:818:in `block in say_with_time’

/home/ec2-user/.rvm/gems/ruby-2.6.3/gems/activerecord-5.1.7/lib/active_record/migration.rb:818:in `say_with_time’

/home/ec2-user/.rvm/gems/ruby-2.6.3/gems/activerecord-5.1.7/lib/active_record/migration.rb:838:in `method_missing’

/home/ec2-user/environment/rails_projects/todo/db/migrate/20200709004220_create_tasks.rb:5:in `block in change’

/home/ec2-user/.rvm/gems/ruby-2.6.3/gems/activerecord-5.1.7/lib/active_record/connection_adapters/abstract/schema_statements.rb:282:in `create_table’

/home/ec2-user/.rvm/gems/ruby-2.6.3/gems/activerecord-5.1.7/lib/active_record/migration.rb:849:in `block in method_missing’

/home/ec2-user/.rvm/gems/ruby-2.6.3/gems/activerecord-5.1.7/lib/active_record/migration.rb:818:in `block in say_with_time’

/home/ec2-user/.rvm/gems/ruby-2.6.3/gems/activerecord-5.1.7/lib/active_record/migration.rb:818:in `say_with_time’

/home/ec2-user/.rvm/gems/ruby-2.6.3/gems/activerecord-5.1.7/lib/active_record/migration.rb:838:in `method_missing’

/home/ec2-user/environment/rails_projects/todo/db/migrate/20200709004220_create_tasks.rb:3:in `change’

/home/ec2-user/.rvm/gems/ruby-2.6.3/gems/activerecord-5.1.7/lib/active_record/migration.rb:792:in `exec_migration’

/home/ec2-user/.rvm/gems/ruby-2.6.3/gems/activerecord-5.1.7/lib/active_record/migration.rb:776:in `block (2 levels) in migrate’

/home/ec2-user/.rvm/gems/ruby-2.6.3/gems/activerecord-5.1.7/lib/active_record/migration.rb:775:in `block in migrate’

/home/ec2-user/.rvm/gems/ruby-2.6.3/gems/activerecord-5.1.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:410:in `with_connection’

/home/ec2-user/.rvm/gems/ruby-2.6.3/gems/activerecord-5.1.7/lib/active_record/migration.rb:774:in `migrate’

/home/ec2-user/.rvm/gems/ruby-2.6.3/gems/activerecord-5.1.7/lib/active_record/migration.rb:953:in `migrate’

/home/ec2-user/.rvm/gems/ruby-2.6.3/gems/activerecord-5.1.7/lib/active_record/migration.rb:1230:in `block in execute_migration_in_transaction’

/home/ec2-user/.rvm/gems/ruby-2.6.3/gems/activerecord-5.1.7/lib/active_record/migration.rb:1298:in `block in ddl_transaction’

/home/ec2-user/.rvm/gems/ruby-2.6.3/gems/activerecord-5.1.7/lib/active_record/connection_adapters/abstract/database_statements.rb:235:in `block in transaction’

/home/ec2-user/.rvm/gems/ruby-2.6.3/gems/activerecord-5.1.7/lib/active_record/connection_adapters/abstract/transaction.rb:194:in `block in within_new_transaction’

/home/ec2-user/.rvm/gems/ruby-2.6.3/gems/activerecord-5.1.7/lib/active_record/connection_adapters/abstract/transaction.rb:191:in `within_new_transaction’

/home/ec2-user/.rvm/gems/ruby-2.6.3/gems/activerecord-5.1.7/lib/active_record/connection_adapters/abstract/database_statements.rb:235:in `transaction’

/home/ec2-user/.rvm/gems/ruby-2.6.3/gems/activerecord-5.1.7/lib/active_record/transactions.rb:210:in `transaction’

/home/ec2-user/.rvm/gems/ruby-2.6.3/gems/activerecord-5.1.7/lib/active_record/migration.rb:1298:in `ddl_transaction’

/home/ec2-user/.rvm/gems/ruby-2.6.3/gems/activerecord-5.1.7/lib/active_record/migration.rb:1229:in `execute_migration_in_transaction’

/home/ec2-user/.rvm/gems/ruby-2.6.3/gems/activerecord-5.1.7/lib/active_record/migration.rb:1201:in `block in migrate_without_lock’

/home/ec2-user/.rvm/gems/ruby-2.6.3/gems/activerecord-5.1.7/lib/active_record/migration.rb:1200:in `each’

/home/ec2-user/.rvm/gems/ruby-2.6.3/gems/activerecord-5.1.7/lib/active_record/migration.rb:1200:in `migrate_without_lock’

/home/ec2-user/.rvm/gems/ruby-2.6.3/gems/activerecord-5.1.7/lib/active_record/migration.rb:1150:in `migrate’

/home/ec2-user/.rvm/gems/ruby-2.6.3/gems/activerecord-5.1.7/lib/active_record/migration.rb:1007:in `up’

/home/ec2-user/.rvm/gems/ruby-2.6.3/gems/activerecord-5.1.7/lib/active_record/migration.rb:985:in `migrate’

/home/ec2-user/.rvm/gems/ruby-2.6.3/gems/activerecord-5.1.7/lib/active_record/tasks/database_tasks.rb:171:in `migrate’

/home/ec2-user/.rvm/gems/ruby-2.6.3/gems/activerecord-5.1.7/lib/active_record/railties/databases.rake:58:in `block (2 levels) in <top (required)>’

/home/ec2-user/.rvm/gems/ruby-2.6.3/gems/rake-13.0.1/exe/rake:27:in `<top (required)>’

/home/ec2-user/.rvm/gems/ruby-2.6.3/bin/ruby_executable_hooks:24:in `eval’

/home/ec2-user/.rvm/gems/ruby-2.6.3/bin/ruby_executable_hooks:24:in `<main>’

Tasks: TOP => db:migrate

(See full trace by running task with –trace)

コマンドを入力し、Enterキーを押しますが、「StandardError: An error has occurred, this and all later migrations canceled:」というエラーが発生します。

エラーの原因を探してみると、

class CreateTasks < ActiveRecord::Migration[5.1]
def change
create_table :tasks do |t|
t.string :title
t.boolean :done, default: false

t.timestamps
end
end
end

「20200709004220_create_tasks.rb」というファイルの「default: fales」の記述が間違っていた。正しくは「default: false」であるので、ファイルを修正する。修正後、再びdb:migrateコマンドを用いる。

ec2-user:~/environment/rails_projects/todo (master) $ rake db:migrate

== 20200709004220 CreateTasks: migrating ======================================

— create_table(:tasks)

   -> 0.0021s

== 20200709004220 CreateTasks: migrated (0.0026s) =============================

用いると今度はエラーが発生しなかった。記述ミスには注意したいところ。

コメント

タイトルとURLをコピーしました