Question

Trying to re-install Devise. Rails 4 on Postgresql

I've followed the instructions from Devise (like adding devise gem/bundle install) and made the changes to my environments/application.rb/added my flash messages

Then ran

rails generate devise User

and got this...

invoke  active_record

    create    db/migrate/20130819025615_add_devise_to_users.rb
    insert    app/models/user.rb
    route  devise_for :users

but the problem is when I try and run rake db:migrate I get this error

== AddDeviseToUsers: migrating =============================================== -- change_table(:users) rake aborted! An error has occurred, this and all later migrations canceled: PG::UndefinedTable: ERROR: relation "users" does not exist : ALTER TABLE "users" ADD COLUMN "email" character varying(255) DEFAULT '' NOT NULL/Users/name/.rvm/gems/ruby-2.0.0-p195/gems/activerecord-4.0.0/lib/active_record/connection_adapters/postgresql/database_statements.rb:128:in exec'

So I understand that the error is telling me that no table 'users' exists, but Devise is supposed to create this, so my main question is... What is the easiest way to fix this?

Also, why didnt Devise create this? Will this cause future problems?

Should I Create a Users table in postgres, and then run the command again in Devise and let it change necessary files and "devise-ify" it? (If it will even do that)

Thanks!

Was it helpful?

Solution

I don't think Devise creates a User table. rails generate devise User simply generates a migration that associates Devise with the User table. In your case, the User table does not exist yet. Hence, the error. First, you should write a migration that creates the User table. For example:

class CreateUsers < ActiveRecord::Migration
  def change
    create_table :users do |t|
    end
  end
end

Then run rake db:migrate. Ensure the migration that creates the table is run before db/migrate/20130819025615_add_devise_to_users.rb by naming the file appropriately.

OTHER TIPS

There are many ways to feed a cat (I am animal friendly)

Method 1: 1. rails db create 2. rails db setup It executes your earlier migrations code and created Users and other migrations.

Method 2: - Create migrations using 'rails generate devise User' - run 'rake db:migrate' This will do a fine job as well.

But, migrations is the way, if you need to add additional fields in the Users table any ways.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top