提交 a3f758ab 编写于 作者: G Guillermo Iguaran 提交者: GitHub

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

Remove FK together with column in MySQL
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册