ActiveRecord :: NotNullViolation in Devise error

【Overview】

1. Conclusion </ b>

2. What is ActiveRecord :: NotNullViolationt </ b>

3. Why ActiveRecord :: NotNullViolation in Devise </ b>

4. How to solve it </ b>

5. Supplement </ b>

  1. Conclusion

in db / migrate / "" "" devise_create "" "" ".rb Delete the "t.string password (or password_confirmation)" </ b> description!


2. What is ActiveRecord :: NotNullViolationt?

スクリーンショット 2020-08-29 20.47.37.png

This means "Items that should not be left blank (NULL) due to DB rules are about to be saved as data! You can't do that!" </ B> It's pointed out!


3. Why ActiveRecord :: NotNullViolation in Devise

When multiplied by 2, it says, "Items that should not be left blank (NULL) on the device are about to be saved as data! It is when it is saved and registered with the controller!" ..

The reason for this is that gem'devise' created a password for me. I'm trying to make it over, so I don't know which password is better and it seems that it became NULL!

gem'devise' is a gem that creates a password and a password_confirmation for it!

So

db/migrate/""""_devise_create_""""".rb


t.string :password null:false"(password_confirmation)

You don't have to program to create columns!


4. How to solve

db/migrate/""""_devise_create_""""".rb


t.string password,  null:false"
(Or password_confirmation)

I think it is written, so let's delete it!

  1. Supplement

By the way, gem'devise' has another feature added to password!

It's validation </ b>!

Since there is already a restriction as a function so that you can not enter unless it is 6 characters or more

model/user


validates :password, length { minimum: 5 }

No need to list!

Recommended Posts