Skip to content

Commit 1cfa4cc

Browse files
author
Zachary Scott
committed
Merge pull request rails#15457 from maurogeorge/add-changing-columns
Create Changing Columns on migrations guides [ci skip]
2 parents 53c26fc + 9477f43 commit 1cfa4cc

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

guides/source/migrations.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,28 @@ end
415415
removes the `description` and `name` columns, creates a `part_number` string
416416
column and adds an index on it. Finally it renames the `upccode` column.
417417

418+
### Changing Columns
419+
420+
Like the `remove_column` and `add_column` Rails provides the `change_column`.
421+
422+
```ruby
423+
change_column :products, :part_number, :text
424+
```
425+
426+
This changes the column part_number on products table to be a text.
427+
428+
Besides the `change_column`, the `change_column_null` and
429+
`change_column_default` are used specifically to change the null and default
430+
values of a column.
431+
432+
```ruby
433+
change_column_null :products, :name, false
434+
change_column_default :products, :approved, false
435+
```
436+
437+
This sets name on products to a NOT NULL column and the default value
438+
of approved as false.
439+
418440
### When Helpers aren't Enough
419441

420442
If the helpers provided by Active Record aren't enough you can use the `execute`

0 commit comments

Comments
 (0)