0

I'm a total newbie with Ruby, Rails, Rake, MySQL (on Ubuntu/bash/command line) and devise (warden 1.2.3, devise 3.0.4). I must continue with what have been done so far : the Rails 4 project is working and linked to a MySQL database (full, populated with users and data). I'm able to change controllers and views.

I must add devise to the project. I'm reading this : https://github.com/plataformatec/devise . My class name is User. So I did rails generate devise User.

When I do rake db:migrate I have this error : Mysql2::Error: Table 'users' already exists: ... of course, since I already have a users table in my project.

Whatever I read ( Devise with Rails 4 ), it's always about create the User model, never how to plug devise on a pre-existing User model.

What document should I read ? Which file I must edit to tell devise "this is my user model and table:" ?

Community
  • 1
  • 1
Eric Lavoie
  • 5,121
  • 3
  • 32
  • 49

2 Answers2

1

If Ruby/Rails is brand new for you, and you're lost.. (like I was...).

  • Look for the migration file (migration-name.rb) in "/yourproject/db/migrate/". This file was generated by rails generate devise User (User can by any Model, like UserAdmin or Client ...). This file tells you the modifications Devise will do to the database (what it needs).

  • Look at this file carefully and make sure that your database match the requirements. If you run rake db:migrate rake will attempt to modify your database. Maybe this is your error (attempt to create a table User, since your table User is already created).

  • Modify your migration file. You may also change your database manually and delete the migration file (if you don't care to keep track of your migrations); in this last case, of course, you don't have to run the rake command.

Eric Lavoie
  • 5,121
  • 3
  • 32
  • 49
0

Follow the Devise getting-started guide, and intelligently apply the manual steps to your current project where necessary.

https://github.com/plataformatec/devise#getting-started

Donovan
  • 15,917
  • 4
  • 22
  • 34
  • 1
    Add Devise to your model, instead of creating a new one. My Guess is that you created a new model, but you didn't delete your old migration. – givanse Dec 18 '13 at 19:39