Maher Manoubi
Maher Manoubi

Reputation: 625

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.

Upvotes: 9

Views: 2553

Answers (2)

Sharvy Ahmed
Sharvy Ahmed

Reputation: 7405

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

Upvotes: 16

AJ Gregory
AJ Gregory

Reputation: 1609

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.

Upvotes: 18

Related Questions