Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rake db:migrate table already exist

I don't understand why this is happening. I have the following migration:

def self.up
  create_table :leakages do |t|
    t.integer :feature_id
    t.integer :project_id
    t.float :total
    t.date :apt_date
  end
  add_index :leakages, [:feature_id, :apt_date]
end

When I run it for the first time it runs properly, but when I run the migration again then an error is thrown saying leakages table already exist. Why is this error occurring? I am using the mysql2 gem.

like image 228
user2406618 Avatar asked Jul 18 '13 06:07

user2406618


1 Answers

You need to drop that table from the sql lite console (You will lost all the data contained in it)

1) Access the sql lite console, type in terminal

sqlite3 db/development.sqlite3 

2) Drop table (dont forget the last ; )

drop table table_name;

3) Exit sql lite console

.quit

4) run db:migrate again

bin/rake db:migrate

Hope it helps, it worked for me

like image 138
Gonza Piotti Avatar answered Oct 13 '22 00:10

Gonza Piotti