Search code examples
ruby-on-railswindowssqliterake

$rake db:migrate An error has occurred, this and all later migrations canceled


I am new to RoR and I keep getting this error message:

$ rake db:migrate
==  CreateUsers: migrating ====================================================
-- create_table(:users)
rake aborted!
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, "name" varchar(255), "email" varchar
(255), "created_at" datetime, "updated_at" datetime)

Tasks: TOP => db:migrate
(See full trace by running task with --trace)

I've been searching for a solution for 3 days, but I cannot seem to find anything that works for me.

Thank you in advance for your help :) PS - I am running off Windows.


Solution

  • table "users" already exists seems to be the problem. Have you tried to manually remove the table from your database with some SQLITE admin tool?

    Or you can include a remove table in your migration script (should be called create_users.rb inside your db/migrate folder). Inside def up insert drop_table :users :

          def up
             drop_table :users
    
             create_table :users do |t|
             t.string :name
             #...
    
             t.timestamps
          end
    

    Oh and I remember from my RoR time that the table name "Users" can cause problems later on. Might be this is related.