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'
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.
You can reset database by using
$ rake db:reset
Or if you want to undo your migration you can use
$ rake db:rollback
Or if you want to update your table, you may change it in your migration file from create_table to change_table
create_table :users do |t|
to
change_table(:users) do |t|
Look like you have not any users migration but you have migration to change the users table.Means you are trying to alter users table without existence of it.If you have schema file then you can load your database from there by using rake db:schema:dump command.
You already have the users table created. Looks like the migration was already run and there is no need to run it again.