instance method
remove_check_constraint
Ruby on Rails 8.0.4
Since v6.1.7.10Signature
remove_check_constraint(table_name, expression = nil, if_exists: false, **options)
Removes the given check constraint from the table. Removing a check constraint that does not exist will raise an error.
remove_check_constraint :products, name: "price_check"
To silently ignore a non-existent check constraint rather than raise an error, use the if_exists option.
remove_check_constraint :products, name: "price_check", if_exists: true
The expression parameter will be ignored if present. It can be helpful to provide this in a migration’s change method so it can be reverted. In that case, expression will be used by #add_check_constraint.
Parameters
-
table_namereq -
expressionopt = nil -
if_existskey = false -
optionskeyrest
Source
# File activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb, line 1327
def remove_check_constraint(table_name, expression = nil, if_exists: false, **options)
return unless supports_check_constraints?
return if if_exists && !check_constraint_exists?(table_name, **options)
chk_name_to_delete = check_constraint_for!(table_name, expression: expression, **options).name
at = create_alter_table(table_name)
at.drop_check_constraint(chk_name_to_delete)
execute schema_creation.accept(at)
end
Defined in activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb line 1327
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveRecord::ConnectionAdapters::SchemaStatements