Permalink
Browse files

Merge pull request #29455 from kirs/remove-column-with-fk-mysql

Remove FK together with column in MySQL
  • Loading branch information...
guilleiguaran committed Jun 17, 2017
2 parents f8f792f + 675a912 commit a3f758ab0ad7d65bf498980f875c8b3c71e347c0
@@ -45,6 +45,13 @@ def indexes(table_name, name = nil)
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")
@@ -139,6 +139,16 @@ class ReferencesForeignKeyTest < ActiveRecord::TestCase
end
end
test "removing column removes foreign key" do
@connection.create_table :testings do |t|
t.references :testing_parent, index: true, foreign_key: true
end
assert_difference "@connection.foreign_keys('testings').size", -1 do
@connection.remove_column :testings, :testing_parent_id
end
end
test "foreign key methods respect pluralize_table_names" do
begin
original_pluralize_table_names = ActiveRecord::Base.pluralize_table_names

0 comments on commit a3f758a

Please sign in to comment.