jakeofalltrades
jakeofalltrades

Reputation: 21

Deleting Rails Tables & Migrations

If the answer to this has already been discussed, please point me in the right direction. I have searched for this problem, but nothing I have found has worked in my case.

I've created tables that I would like to delete. I have deleted the models and the migrations, but when I attempt to recreate them then migrate, I get the following:

SQLite3::SQLException: table already exists, etc....

I've attempted to use an SQLite manager to delete them manually, but I'm not sure where the database file is located (other posts didn't help me here either). I am on Win 7, by the way.

I would like to know the proper way of doing this.

Upvotes: 2

Views: 5948

Answers (3)

Kishore Mohan
Kishore Mohan

Reputation: 1060

This is another easiest way of creating table and migration again. If you are using rails 3. run this commands to drop database and create it again .

rake db:drop # to drop database

rake db:create # to create same database

rake db:migrate # to migrate the data.

Upvotes: 7

muttonlamb
muttonlamb

Reputation: 6501

I've written a blog post on dealing with this kind of scenario, it may be helpful...

http://www.fmhcc.com.au/ruby/database-migrations-in-rails-and-when-to-start-from-scratch/

Upvotes: 0

Ian Kenney
Ian Kenney

Reputation: 6426

you can generate a migration

 rails generate migration DropProducts

and use it to drop the table

class DropProducts < ActiveRecord::Migration
  def up
    drop_table :products    
  end
end

Upvotes: 4

Related Questions