instance method add_column

Ruby on Rails 2.2.3

Since v2.2.3 Last seen in v3.2.22.5

Available in: v2.2.3 v2.3.18 v3.0.20 v3.1.12 v3.2.22.5

Signature

add_column(table_name, column_name, type, options = {})

Adds a new column to the named table. See TableDefinition#column for details of the options you can use.

Parameters

table_name req
column_name req
type req
options opt = {}
Source
# File activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb, line 801
      def add_column(table_name, column_name, type, options = {})
        default = options[:default]
        notnull = options[:null] == false

        # Add the column.
        execute("ALTER TABLE #{quote_table_name(table_name)} ADD COLUMN #{quote_column_name(column_name)} #{type_to_sql(type, options[:limit], options[:precision], options[:scale])}")

        change_column_default(table_name, column_name, default) if options_include_default?(options)
        change_column_null(table_name, column_name, false, default) if notnull
      end

Defined in activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb line 801 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActiveRecord::ConnectionAdapters::PostgreSQLAdapter

Type at least 2 characters to search.

↑↓ navigate · open · esc close