Rake aborted... table 'users' already exists

If you wanna play safe and don't want to lose any data then you can check if the table exists in your database.

class DeviseCreateUsers < ActiveRecord::Migration
  def up
    if table_exists?(:users)
      # update or modify columns of users table here accordingly.
    else
      # create table and dump the schema here
    end
  end

  def down
    # same approach goes here but in the reverse logic
  end
end

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
    mysql <DB NAME HERE>

  2. Drop table (dont forget the last ; (semicolon))
    drop table table_name;

  3. run db:migrate again
    bin/rake db:migrate

Hope it helps, it worked for me


The migration is trying to create a table that already exists in your database.

Try to remove the user table from your database. Something went wrong with you migration process. You should also compare your schema.rb version with your db/migrate/*.rb files.

Clarification:

It seems that many SO users don't agree with my reply, either because they consider it inaccurate or not recommended.

Removing a table is always destructive, and I think that everyone understands that.

I should have mentioned add_column, since the table was being created in another migration file.


In your create_users migration (APP_ROOT/db/migrate/..), add drop_table :users right before create_table :users and run rake db:migrate. It will remove the users table before recreating it. You can remove that line of code after running this migration so it doesn't give you errors later on. Just a small fix if you dont have UI access to a database (on heroku, for example).