试图在Rails 4中删除表/迁移的问题

时间:2014-06-19 17:34:33

标签: ruby-on-rails

我尝试使用相同模型(comment.rb)作为我之前尝试安装的gem之一来实现。我已经尝试过rake db:rollback和rake db:rollback VERSION =回到我不应该进行任何迁移或任何名为' comment'的表,但是sqlite3一直在告诉我有一个带有该名称的表格,它无法前进。

rake db:migrate:status

     Status   Migration ID    Migration Name
    --------------------------------------------------
       up     20140616150625  Devise create users
       up     20140616151746  Create hacks
       up     20140616155718  Acts as taggable on migration.acts as taggable on engine
       up     20140616155719  Add missing unique indices.acts as taggable on engine
       up     20140616155720  Add taggings counter cache to tags.acts as taggable on engine
       up     20140617185601  Add picture to hacks
       up     20140617190705  Add attachment image to hacks
       up     20140617194434  Add name to users
       up     20140617194509  Create identities
       up     20140618125514  Add confirmable to devise
       up     20140619150148  Create comments
       up     20140619162204  The comments change user.the comments engine
      down    20140619162205  The comments create comments.the comments engine
      down    20140619162206  The comments change commentable.the comments engine
      down    20140619163035  Drop comments

问题是 - 我不确定这是否称为机架跟踪?

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

SQLite3::SQLException: table "comments" already exists: CREATE TABLE "comments" ("id"   INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "user_id" integer, "holder_id" integer,  "commentable_id" integer, "commentable_type" varchar(255), "commentable_url" varchar(255), "commentable_title" varchar(255), "commentable_state" varchar(255), "anchor" varchar(255), "title" varchar(255), "contacts" varchar(255), "raw_content" text, "content" text, "view_token" varchar(255), "state" varchar(255) DEFAULT 'draft', "ip" varchar(255) DEFAULT 'undefined', "referer" varchar(255) DEFAULT 'undefined', "user_agent" varchar(255) DEFAULT 'undefined', "tolerance_time" integer, "spam" boolean DEFAULT 'f', "parent_id" integer, "lft" integer, "rgt" integer, "depth" integer DEFAULT 0, "created_at" datetime, "updated_at" datetime) /Users/javier/.rvm/gems/ruby-2.1.2/gems/sqlite3-1.3.9/lib/sqlite3/database.rb:91:in `initialize'

我试图通过访问sqlite3来删除同一个表,但是我无法访问这些表。有什么建议吗?

1 个答案:

答案 0 :(得分:0)

您创建了onesecond表格comments进行了两次迁移。 DB无法创建具有相同名称的第二个表。

关于迁移。主要详细信息可在guides中找到。

rollback不会删除迁移 - 它只是将其还原(运行方法向下)。如果您想使用第二个表格comments,您至少有两种方式:

  1. 回滚创建第一个表。删除迁移(删除物理文件)。运行rake db:migrate

  2. 您可以创建一个新的迁移,drop_table comments然后使用新版本的表comments生成新的迁移(使用drop table迁移的时间戳小于迁移的时间戳非常重要与创建表)。在此次运行rake db:migrate

  3. 之后