Philip7899
Philip7899

Reputation: 4677

rails 4 devise error: SQLite3::SQLException: table users has no column named password

This is really weird. I've used Devise hundreds of times and never gotten this error. Here is my model:

class User < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable
end

and here is the schema:

  create_table "users", force: :cascade do |t|
    t.string   "email",                  limit: 255, default: "", null: false
    t.string   "encrypted_password",     limit: 255, default: "", null: false
    t.string   "reset_password_token",   limit: 255
    t.datetime "reset_password_sent_at"
    t.datetime "remember_created_at"
    t.integer  "sign_in_count",                      default: 0,  null: false
    t.datetime "current_sign_in_at"
    t.datetime "last_sign_in_at"
    t.string   "current_sign_in_ip",     limit: 255
    t.string   "last_sign_in_ip",        limit: 255
    t.datetime "created_at",                                      null: false
    t.datetime "updated_at",                                      null: false
    t.string   "first_name",             limit: 255
    t.string   "last_name",              limit: 255
    t.string   "type",                   limit: 255
    t.integer  "patient_id"
  end

  add_index "users", ["email"], name: "index_users_on_email", unique: true
  add_index "users", ["patient_id"], name: "index_users_on_patient_id"
  add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true

I go into the rails console and type:

u = User.create(email:'[email protected]', password: 'password', password_confirmation: 'password')

and somehow I get this error:

2.2.0 :001 > u = User.create(email:'[email protected]', password: 'password', password_confirmation: 'password')
   (0.1ms)  begin transaction
  User Exists (0.2ms)  SELECT  1 AS one FROM "users" WHERE "users"."email" = '[email protected]' LIMIT 1
  SQL (0.1ms)  INSERT INTO "users" ("email", "password", "encrypted_password", "created_at", "updated_at") VALUES (?, ?, ?, ?, ?)  [["email", "[email protected]"], [nil, nil], ["encrypted_password", "$2a$11$XAjcHN39soOIk6xh9CckmOFc7osxpsHfwCX/ASsLXwsRac/UItIli"], ["created_at", "2016-04-06 16:49:47.400937"], ["updated_at", "2016-04-06 16:49:47.400937"]]
SQLite3::SQLException: table users has no column named password: INSERT INTO "users" ("email", "password", "encrypted_password", "created_at", "updated_at") VALUES (?, ?, ?, ?, ?)
   (0.0ms)  rollback transaction
ActiveRecord::StatementInvalid: SQLite3::SQLException: table users has no column named password: INSERT INTO "users" ("email", "password", "encrypted_password", "created_at", "updated_at") VALUES (?, ?, ?, ?, ?)

What's going wrong? I've installed the devise_token_auth gem but haven't implemented it yet, so I don't know what that could have done.

Upvotes: 0

Views: 245

Answers (1)

Philip7899
Philip7899

Reputation: 4677

This ended up being a gem versioning issue. I had rails in the gemfile like so:

gem 'rails', '4.2.0'

After replacing it with:

gem 'rails'

and running bundle update, the problem stopped.

Upvotes: 1

Related Questions