开发者

Drop_table problem preventing rake db:migrate

I was looking for a way to drop a table in Rails and start fresh and came across this answer: Rails DB Migration - How To Drop a Table?

However, when I ran drop_table :examples I got the following error:

-bash: drop_table: command not found

Here's my create_examples migrate file:

def self.down
  drop_table :examples
end

Can anyone help guide me into fixing this and give me insight on what I'm doing wrong? I need to fix it because this particular migrate is preventing from doing a rake db:migrate, generating the following error:

==  CreateExamples: migrating ====================================================
-- create_table(:examples)
rake aborted!
An error has occurred, this and all later migrations canceled:

SQLite3::SQLException: table "examples" already exists: CREATE TABLE "examples" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "content" varchar(255), "user_id" integer, "created_at" datetime, "updated_at" datetime) 
开发者_如何学编程

Thanks! (And if I need to provide more code let me know.)


You should be dropping your old table right before creating the new version:

def self.up
    drop_table :examples
    create_table :examples do |t|
        #...
    end
end

And since you can't really reverse that drop_table, you might want to raise an exception in the rollback:

def self.down
    raise ActiveRecord::IrreversibleMigration
end

Or maybe you just want to keep your current self.down.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜