2015-10-20 131 views
1

當我運行此命令斌/耙分貝:遷移錯誤斌/耙分貝:遷移

我得到這個錯誤

== 20151020021106 CreateTodoItems: migrating ================================== -- create_table(:todo_items) rake aborted! StandardError: An error has occurred, this and all later migrations canceled:

SQLite3::SQLException: table "todo_items" already exists: CREATE TABLE "todo_items" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "todo_list_id" integer, "content" varchar, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL) /home/youta/rails_projects/odot/db/migrate/20151020021106_create_todo_items.rb:3:in change' -e:1:in' ActiveRecord::StatementInvalid: SQLite3::SQLException: table "todo_items" already exists: CREATE TABLE "todo_items" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "todo_list_id" integer, "content" varchar, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL) /home/youta/rails_projects/odot/db/migrate/20151020021106_create_todo_items.rb:3:in change' -e:1:in' SQLite3::SQLException: table "todo_items" already exists /home/youta/rails_projects/odot/db/migrate/20151020021106_create_todo_items.rb:3:in change' -e:1:in' Tasks: TOP => db:migrate (See full trace by running task with --trace)

爲了解決這個問題,我嘗試用去除模型todo_item這些命令

耙分貝:回滾

鐵軌破壞模型todo_item

耙分貝:滴

耙分貝:設置

耙分貝:降RAILS_ENV =測試

耙分貝:設置RAILS_ENV =測試

雖然當我試圖消除後重拍todo_item模型前一個我仍然得到相同的錯誤!

我應該重置混帳..如果是這樣,我怎麼能恢復到以前的工作版本

回答

0

運行rake db:setup是不一樣的運行所有遷移,但使用您的schema.rb重建數據庫,其中仍包括todo_items表。

rake db:drop再次刪除數據庫,然後運行rake db:migrate以僅使用migrate目錄中的遷移。

+0

謝謝你,它像一個魅力 – youta