diff options
author | Andrew White <andrew.white@unboxed.co> | 2016-11-02 16:49:18 +0000 |
---|---|---|
committer | Andrew White <andrew.white@unboxed.co> | 2016-11-02 16:49:18 +0000 |
commit | 6e167d38e25186419ef26e9755ba6f4e3f709722 (patch) | |
tree | abb8b69a7c235b91048cc249d44f89cc76877915 /activerecord/lib | |
parent | 4f2de3480c8bbdb928e3b3c6e71674f8c5992a60 (diff) | |
download | rails-6e167d38e25186419ef26e9755ba6f4e3f709722.tar.gz rails-6e167d38e25186419ef26e9755ba6f4e3f709722.tar.bz2 rails-6e167d38e25186419ef26e9755ba6f4e3f709722.zip |
Fix raising uniqueness constraints in newer versions of SQLite
Versions 3.8.2 and later of SQLite changed the formatting of the error
messages returned when a uniqueness constraint was violated.
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb index 455560aa55..f3a47ba80a 100644 --- a/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb @@ -571,7 +571,11 @@ module ActiveRecord def translate_exception(exception, message) case exception.message - when /column(s)? .* (is|are) not unique/ + # SQLite 3.8.2 returns a newly formatted error message: + # UNIQUE constraint failed: *table_name*.*column_name* + # Older versions of SQLite return: + # column *column_name* is not unique + when /column(s)? .* (is|are) not unique/, /UNIQUE constraint failed: .*/ RecordNotUnique.new(message, exception) else super |