Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 4.1 Devise 3.3 column users.password does not exist

I want to create a user manually through the console as such:

User.find_or_create_by(email: "[email protected]", first_name: "Stan", last_name: "Smith", password: "password", password_confirmation: "password", confirmed_at: Time.now)

I have done this many times in past projects but this time it's not working. It is not picking up the Devise password model attribute so this is the error I get:

PG::UndefinedColumn: ERROR:  column users.password does not exist

I have Rails 4.1.4 and Devise 3.3.0. Did something change in the latest versions?

Thanks.

like image 601
Maher Manoubi Avatar asked Aug 26 '14 03:08

Maher Manoubi


2 Answers

Instead of User.find_or_create_by you should be using User.create.

Devise accepts a password and password confirmation on creation but the actual table only has a column called encrypted_password.

The "find" portion of User.find_or_create_by is looking for a column called "password" which doesn't exist.

like image 70
AJ Gregory Avatar answered Oct 20 '22 03:10

AJ Gregory


Still if you want to use find_or_create_by, it accepts block:

User.find_or_create_by(email: "[email protected]", first_name: "Stan", last_name: "Smith") do |user|
  user.password = "password"
  user.confirmed_at = Time.now
end
like image 40
Sharvy Ahmed Avatar answered Oct 20 '22 05:10

Sharvy Ahmed