# Automatically populating models with the defaults from the table definition

**URL:** <https://www.ruby-forum.com/t/automatically-populating-models-with-the-defaults-from-the-table-definition/128473>\
**Category:** Rails\
**Created:** [February 7, 2008, 11:33pm UTC](https://www.ruby-forum.com/t/automatically-populating-models-with-the-defaults-from-the-table-definition/128473 "2008-02-07T23:33:04Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tim\_U](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/90db22/32.png) [@Tim\_U](https://www.ruby-forum.com/u/Tim_U)\
**Post date:** [February 7, 2008, 11:33pm UTC](https://www.ruby-forum.com/t/automatically-populating-models-with-the-defaults-from-the-table-definition/128473/1 "2008-02-07T23:33:04Z")

</div>

I am using SQL server with ODBC adapter. If I have a field defined as  
“hair\_color string(255) default(“UNK”), not null” it causes  
problems with saving the record if I don’t specify the hair color.

In this case if I don’t specify a hair color AR puts a NULL into the  
insert clause and SQL server pukes. If AR simply had left that field  
out of the insert everything would have been fine.

Is there a way to tell AR to either leave the NULL fields out of the  
insert (or update) or to load the defaults into the model when it’s  
created?

Thanks.
