69
70

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

rakeで謎のエラーが出る(StandardError: An error has occurred, this and all later migrations canceled:)

Last updated at Posted at 2016-12-26

環境をどんどん変えていっていたらいろんなエラーに悩まされたのですが、これだけはググってもなかなか出てこなかったので共有します、というより備忘録として…。

とあるテキストをやっていて(Railsの超有名なやつ)、突然こんなエラーが出てきました。

$ rake db:migrate
== 20161226043813 CreateBooks: migrating ======================================
-- create_table(:books)
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:

SQLite3::SQLException: table "books" already exists: CREATE TABLE "books" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "isbn" varchar, "title" varchar, "price" integer, "publish" varchar, "published" date, "cd" boolean, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL)
/Users/fndm40/rwork/railbook/db/migrate/20161226043813_create_books.rb:3:in `change'
ActiveRecord::StatementInvalid: SQLite3::SQLException: table "books" already exists: CREATE TABLE "books" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "isbn" varchar, "title" varchar, "price" integer, "publish" varchar, "published" date, "cd" boolean, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL)
/Users/fndm40/rwork/railbook/db/migrate/20161226043813_create_books.rb:3:in `change'
SQLite3::SQLException: table "books" already exists
/Users/fndm40/rwork/railbook/db/migrate/20161226043813_create_books.rb:3:in `change'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)

何度rakeしてもダメですし、rakeコマンドに問題があるのかと思い

$ bundle update rake

をやってみてもダメでした。
エラー文をよく見てみると「既にbooksテーブルは存在しています」と書いているので、一旦DBをリセットすることにしました。
一応コマンドです。

$ rake db:migrate:reset

このあとにもう一度

$ rake db:migrate

を実行したら無事に解決しました。
めでたしめでたし。

69
70
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
69
70

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?