【问题标题】:Error in bin/rake db:migratebin/rake db 中的错误:迁移
【发布时间】:2016-01-19 04:02:38
【问题描述】:

当我运行这个命令时 bin/rake db:migrate

我收到此错误

== 20151020021106 CreateTodoItems:迁移 =================================== -- create_table(:todo_items)耙中止! StandardError:发生错误,此迁移和所有后续迁移已取消:

SQLite3::SQLException: 表 "todo_items" 已经存在: 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: 表“todo_items”已经存在: 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: 表“todo_items”已经存在/home/youta/rails_projects/odot/db/migrate/20151020021106_create_todo_items.rb:3: in change' -e:1:in' Tasks: TOP => db:migrate(通过使用 --trace 运行任务查看完整跟踪)

为了解决这个问题,我尝试使用这些命令删除模型 todo_item

rake db:回滚

rails 销毁模型 todo_item

rake db:drop

耙数据库:设置

rake db:drop RAILS_ENV=test

rake db:setup RAILS_ENV=test

虽然当我在删除前一个模型后尝试重新制作 todo_item 模型时,我仍然遇到同样的错误!

我应该重置 git .. 如果是这样,我怎样才能将其重置为以前的工作版本

【问题讨论】:

    标签: ruby-on-rails


    【解决方案1】:

    运行rake db:setup 与运行所有迁移不同,而是使用您的schema.rb 重建数据库,其中仍然包括todo_items 表。

    使用rake db:drop 再次删除数据库,然后运行rake db:migrate 以仅使用migrate 目录中的迁移。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-05
      • 1970-01-01
      • 2011-11-06
      • 2011-04-29
      • 2012-06-16
      • 2012-12-09
      相关资源
      最近更新 更多