instance method remove_check_constraint

Ruby on Rails 8.1.2

Since v6.1.7.10

Available in: v6.1.7.10 v7.0.10 v7.1.6 v7.2.3 v8.0.4 v8.1.2

Signature

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_name req
expression opt = nil
if_exists key = false
options keyrest
Source
# File activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb, line 1357
      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 1357 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActiveRecord::ConnectionAdapters::SchemaStatements

Type at least 2 characters to search.

↑↓ navigate · open · esc close