While creating a web service that I thought about for the first time with rails, I suddenly got angry when creating a new user
unknown attribute 'password' for User. def create @user = User.new( name: params[:name], email: params[:email], password: params[:password]
I was told that there is no password column, so I will check the columns in the Users table.
$ rails console $ User.new Loading development environment (Rails 22.214.171.124) irb(main):001:0> User.new (7.5ms) SELECT sqlite_version(*) => #<User id: nil, name: nil, email: nil, created_at: nil, updated_at: nil>
Certainly there is no password column. The password column should have been created in the users table by creating a migration file, but ... Let's take a look at the migration file
class AddPasswordToUsers < ActiveRecord::Migration[6.0] def change add_column: :users, :password, :string end end
There was an extra colon after add_column
I corrected the code mistake and rails db: migrate and it worked. It was a rudimentary mistake so I want to be careful