Adam Rice
Adam Rice

Reputation: 1

Error during migration while setting up Devise

I'm relatively new to Rails and I'm running into an issue while trying to set up Devise. I believe the issue stems from the fact that I already generated a user scaffold before trying to install Devise, yet I don't know how to solve this problem. When I proceed through the Devise setup, I get to the step where I have to enter the following code:

rails generate devise User

That works, and I get this back from terminal:

invoke  active_record
  create    db/migrate/20120609032448_add_devise_to_users.rb
  insert    app/models/user.rb
   route  devise_for :users

The next step is to migrate the database, which I attempt but get the following error:

==  AddDeviseToUsers: migrating ===============================================
-- change_table(:users)
rake aborted!
An error has occurred, this and all later migrations canceled:

SQLite3::SQLException: duplicate column name: email: ALTER TABLE "users" ADD "email"         varchar(255) DEFAULT '' NOT NULL

Tasks: TOP => db:migrate

I've tried destroying the original User scaffold along with the original User migration but I keep getting stuck at this error. Help would be much appreciated!

Upvotes: 0

Views: 1748

Answers (2)

cluu
cluu

Reputation: 13

Try going to this file

db/migrate/20120609032448_add_devise_to_users.rb 

and in the code where it says

change_table(:users)...

alter this to

create_table(:users)...

Upvotes: 0

Ben Kreeger
Ben Kreeger

Reputation: 6344

Your new migration probably has an email column defined in it. Comment that line regarding adding an email column out and run it again. It's likely you've already got an email column in your model.

Upvotes: 3

Related Questions