File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change 415
415
removes the ` description ` and ` name ` columns, creates a ` part_number ` string
416
416
column and adds an index on it. Finally it renames the ` upccode ` column.
417
417
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
+
418
440
### When Helpers aren't Enough
419
441
420
442
If the helpers provided by Active Record aren't enough you can use the ` execute `
You can’t perform that action at this time.
0 commit comments