From 9ae1a2c69f51a9065090a9c505f4d22ffbb84094 Mon Sep 17 00:00:00 2001 From: Yves Senn Date: Wed, 11 Jun 2014 11:16:31 +0200 Subject: fk: raise when identifiers are longer than `allowed_index_name_length`. --- .../active_record/connection_adapters/abstract/schema_statements.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'activerecord/lib/active_record/connection_adapters') diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb index 18e73b0200..5a863717e5 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb @@ -682,7 +682,11 @@ module ActiveRecord def foreign_key_name(table_name, options) # :nodoc: options.fetch(:name) do - "#{table_name}_#{options.fetch(:column)}_fk" + identifier = "#{table_name}_#{options.fetch(:column)}_fk" + if identifier.length > allowed_index_name_length + raise ArgumentError, "Foreign key name '#{identifier}' is too long; the limit is #{allowed_index_name_length} characters" + end + identifier end end -- cgit v1.2.3