diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2016-06-21 00:38:48 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2016-12-06 16:51:20 +0900 |
commit | b270bc4ad021f051214420de1278627b1924b3b3 (patch) | |
tree | 2e977be2166a36858fd9fc657baebac8c934fbf8 /activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb | |
parent | e10617303475488974fbe635d427f793faeb3f05 (diff) | |
download | rails-b270bc4ad021f051214420de1278627b1924b3b3.tar.gz rails-b270bc4ad021f051214420de1278627b1924b3b3.tar.bz2 rails-b270bc4ad021f051214420de1278627b1924b3b3.zip |
Translate NOT NULL violation to the specific exception
Raise `ActiveRecord::NotNullViolation` when a record cannot be inserted
or updated because it would violate a not null constraint.
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb index 263456a6a3..5262141995 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -408,6 +408,7 @@ module ActiveRecord # See http://www.postgresql.org/docs/current/static/errcodes-appendix.html VALUE_LIMIT_VIOLATION = "22001" + NOT_NULL_VIOLATION = "23502" FOREIGN_KEY_VIOLATION = "23503" UNIQUE_VIOLATION = "23505" SERIALIZATION_FAILURE = "40001" @@ -423,6 +424,8 @@ module ActiveRecord InvalidForeignKey.new(message) when VALUE_LIMIT_VIOLATION ValueTooLong.new(message) + when NOT_NULL_VIOLATION + NotNullViolation.new(message) when SERIALIZATION_FAILURE SerializationFailure.new(message) when DEADLOCK_DETECTED |