From 1bfc1008a7b1e06b3975b349df259187f08532a3 Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Thu, 30 Mar 2017 13:43:26 -0500 Subject: [PATCH] Add Remove The Default Value On A Column as a rails til --- README.md | 3 ++- rails/remove-the-default-value-on-a-column.md | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 rails/remove-the-default-value-on-a-column.md diff --git a/README.md b/README.md index b01b19e..b954415 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ variety of languages and technologies. These are things that don't really warrant a full blog post. These are mostly things I learn by pairing with smart people at [Hashrocket](http://hashrocket.com/). -_517 TILs and counting..._ +_518 TILs and counting..._ --- @@ -346,6 +346,7 @@ _517 TILs and counting..._ - [Polymorphic Path Helpers](rails/polymorphic-path-helpers.md) - [Pretend Generations](rails/pretend-generations.md) - [Read-Only Models](rails/read-only-models.md) +- [Remove The Default Value On A Column](rails/remove-the-default-value-on-a-column.md) - [Rescue From](rails/rescue-from.md) - [Retrieve An Object If It Exists](rails/retrieve-an-object-if-it-exists.md) - [Select A Select By Selector](rails/select-a-select-by-selector.md) diff --git a/rails/remove-the-default-value-on-a-column.md b/rails/remove-the-default-value-on-a-column.md new file mode 100644 index 0000000..6a45d92 --- /dev/null +++ b/rails/remove-the-default-value-on-a-column.md @@ -0,0 +1,16 @@ +# Remove The Default Value On A Column + +You have a column on one of your database tables with a default value. You'd +like to remove the default value. Removing the default is the same as +setting it to `nil`. You can do this with the ActiveRecord DSL using the +`change_column_default` method. + +```ruby +def change + change_column_default :users, :age, nil +end +``` + +See [the +docs](http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/SchemaStatements.html#method-i-change_column_default) +for more details.