简体   繁体   中英

Rails throwing ActiveRecord::StatementInvalid PG::NotNullViolation: ERROR

I recently added bootstrap-datepicker-rails. Now when I try to save a record and I do not enter a date, I receive the active record error above. I have validations set up - why wont it throw a more user friendly error? How can I get this to provide a user friendly error? I am using rails 4.2.7 and ruby 2.3.1.

The problem is you have only added database level not null validation.

Add model level validation as well and you will get well formatted error message

validates :date, presence: true

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM