Rails errors

Rollback Transaction Error in Devise Model for Rails

A memo about dealing with rollback transaction errors in Devise model for Ruby on Rails 5. Devise internally requires email addresses and passwords, and throws errors if they are missing, but those errors are only for the Controller…

Shou Arisaka
1 min read
Oct 31, 2025

A memo about dealing with rollback transaction errors in Devise model for Ruby on Rails 5.

This kind of error occurs:

irb(main):006:0> User.create(username: 'yuis')
   (0.0ms)  begin transaction
   (0.0ms)  rollback transaction
=> #<User id: nil, email: "", created_at: nil, updated_at: nil, provider: nil, uid: nil, username: "yuis", disc: nil>

Cause: Devise internally requires email addresses and passwords, and throws errors if they are missing, but those errors are only for the Controller, so errors are not output. You might notice if you have double validation/constraints in the database, but if not, it’s hard to notice.

Solution: Properly enter email address and password too

irb(main):005:0> User.create(username: 'yuis' , email: '[email protected]' , password: "hogehoge" )
...
=> #<User id: 9, email: "[email protected]", created_at: "2018-07-06 20:51:19", updated_at: "2018-07-06 20:51:19", provider: nil, uid: nil, username: "yuis", disc: nil>

It seems there’s also a possibility that the email address validation regex pattern is wrong, but I think this possibility is actually more likely.

Rollback Transaction Error - Rails - Stack Overflow

Share this article

Shou Arisaka Oct 31, 2025

🔗 Copy Links