Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rake db:migrate error tables

I am trying to run rake db:migrate and am receiving an error in the console.

It seems as though I am creating a table that already exists, yet I don't know how to remove the old table, or reset the db to start fresh.

I don't have any users so erasing or starting from fresh won't be an issue.

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

SQLite3::SQLException: table "users" already exists: CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "email" varchar(255) DEFAULT '' NOT NULL, "encrypted_password" varchar(255) DEFAULT '' NOT NULL, "reset_password_token" varchar(255), "reset_password_sent_at" datetime, "remember_created_at" datetime, "sign_in_count" integer DEFAULT 0 NOT NULL, "current_sign_in_at" datetime, "last_sign_in_at" datetime, "current_sign_in_ip" varchar(255), "last_sign_in_ip" varchar(255), "created_at" datetime, "updated_at" datetime) /Users/jovanhernandez/.rvm/gems/ruby-2.1.2/gems/sqlite3-1.3.9/lib/sqlite3/database.rb:91:in `initialize'


1 Answers

If you don't mind erasing data you can run

rake db:drop
rake db:create
rake db:migrate

and that should fix it. Otherwise you can for the moment comment out the part of the content causing problems in the change (or up) method in your migration and then run the migrations. After the migration is run uncomment the migration.

Doing this tricks rails into accepting that the migrations are up to date.

like image 142
Albin Avatar answered Mar 05 '26 21:03

Albin