aboutsummaryrefslogtreecommitdiffstats
path: root/guides
diff options
context:
space:
mode:
authorZachary Scott <e@zzak.io>2014-06-01 13:59:22 -0700
committerZachary Scott <e@zzak.io>2014-06-01 13:59:22 -0700
commit1cfa4cc23d95887916ca145a72826f2561e033ac (patch)
treeba8aba9270db8aeb6ce04a04a142888c3c33615f /guides
parent53c26fcaee58e15eb4f11ce250c09a3015e0e1a1 (diff)
parent9477f4372fac1a18aad6fbce249a1bfc03e0b61f (diff)
downloadrails-1cfa4cc23d95887916ca145a72826f2561e033ac.tar.gz
rails-1cfa4cc23d95887916ca145a72826f2561e033ac.tar.bz2
rails-1cfa4cc23d95887916ca145a72826f2561e033ac.zip
Merge pull request #15457 from maurogeorge/add-changing-columns
Create Changing Columns on migrations guides [ci skip]
Diffstat (limited to 'guides')
-rw-r--r--guides/source/migrations.md22
1 files changed, 22 insertions, 0 deletions
diff --git a/guides/source/migrations.md b/guides/source/migrations.md
index 6742c05946..221251adf4 100644
--- a/guides/source/migrations.md
+++ b/guides/source/migrations.md
@@ -415,6 +415,28 @@ end
removes the `description` and `name` columns, creates a `part_number` string
column and adds an index on it. Finally it renames the `upccode` column.
+### Changing Columns
+
+Like the `remove_column` and `add_column` Rails provides the `change_column`.
+
+```ruby
+change_column :products, :part_number, :text
+```
+
+This changes the column part_number on products table to be a text.
+
+Besides the `change_column`, the `change_column_null` and
+`change_column_default` are used specifically to change the null and default
+values of a column.
+
+```ruby
+change_column_null :products, :name, false
+change_column_default :products, :approved, false
+```
+
+This sets name on products to a NOT NULL column and the default value
+of approved as false.
+
### When Helpers aren't Enough
If the helpers provided by Active Record aren't enough you can use the `execute`