diff options
author | Kir Shatrov <shatrov@me.com> | 2017-06-14 22:39:19 -0400 |
---|---|---|
committer | Kir Shatrov <shatrov@me.com> | 2017-06-16 20:49:09 -0400 |
commit | 675a912eb86a9e109e9877379e8454b388242d57 (patch) | |
tree | ecab51147d760a892965f570e790a2e6f482765d /activerecord/lib/active_record | |
parent | f1e42fe267342ffa4cea84cf09b0caaee733632c (diff) | |
download | rails-675a912eb86a9e109e9877379e8454b388242d57.tar.gz rails-675a912eb86a9e109e9877379e8454b388242d57.tar.bz2 rails-675a912eb86a9e109e9877379e8454b388242d57.zip |
Remove FK together with column in MySQL
Unlike with other databses, MySQL doesn't let you remove the column
if there's a FK on this column.
For better developer experience we want to remove the FK together with
the column.
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/mysql/schema_statements.rb | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/mysql/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/mysql/schema_statements.rb index f9e1e046ea..fc57e41fc9 100644 --- a/activerecord/lib/active_record/connection_adapters/mysql/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/mysql/schema_statements.rb @@ -45,6 +45,13 @@ module ActiveRecord indexes end + def remove_column(table_name, column_name, type = nil, options = {}) + if foreign_key_exists?(table_name, column: column_name) + remove_foreign_key(table_name, column: column_name) + end + super + end + def internal_string_options_for_primary_key super.tap do |options| if CHARSETS_OF_4BYTES_MAXLEN.include?(charset) && (mariadb? || version < "8.0.0") |