# Generate a migration (from a plugin) to add a column with a default value to an existing table

**URL:** <https://www.ruby-forum.com/t/generate-a-migration-from-a-plugin-to-add-a-column-with-a-default-value-to-an-existing-table/158731>\
**Category:** Rails\
**Created:** [January 27, 2009, 12:03pm UTC](https://www.ruby-forum.com/t/generate-a-migration-from-a-plugin-to-add-a-column-with-a-default-value-to-an-existing-table/158731 "2009-01-27T12:03:02Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![bide](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/4da419/32.png) [@bide](https://www.ruby-forum.com/u/bide)\
**Post date:** [January 27, 2009, 12:03pm UTC](https://www.ruby-forum.com/t/generate-a-migration-from-a-plugin-to-add-a-column-with-a-default-value-to-an-existing-table/158731/1 "2009-01-27T12:03:02Z")

</div>

I add a column to an existing table via the generator with the  
following action:

def cmi\_local\_assigns  
returning(assigns = {}) do  
assigns[:migration\_action] = “add”  
assigns[:class\_name] = “cmi\_add\_avatar\_to\_user#{class\_name}”  
assigns[:table\_name] = args[1]  
assigns[:attributes] = [Rails::Generator::GeneratedAttribute.new  
(“user\_avatar”, “string”)]  
end  
end

This works fine, bug now I want to add a default value for the newly  
created column.  
How is this possible?  
The Rails::Generator::GeneratedAttribute.new allows just two  
parameters.

Any ideas?  
Thanks,  
Bernd
