instance method foreign_key

Ruby on Rails 6.0.6

Since v5.2.8.1

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

Signature

foreign_key(*args, **options)

Adds a foreign key to the table using a supplied table name.

t.foreign_key(:authors)
t.foreign_key(:authors, column: :author_id, primary_key: "id")

See connection.add_foreign_key

Parameters

args rest
options keyrest
Source
# File activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb, line 694
      def foreign_key(*args, **options)
        @base.add_foreign_key(name, *args, **options)
      end

Defined in activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb line 694 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActiveRecord::ConnectionAdapters::Table

Type at least 2 characters to search.

↑↓ navigate · open · esc close