# Getting unexpected string value for NULL values

**URL:** <https://www.ruby-forum.com/t/getting-unexpected-string-value-for-null-values/145746>\
**Category:** Rails\
**Created:** [August 13, 2008, 4:22pm UTC](https://www.ruby-forum.com/t/getting-unexpected-string-value-for-null-values/145746 "2008-08-13T16:22:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e19b73/32.png) [@jeff](https://www.ruby-forum.com/u/jeff)\
**Post date:** [August 13, 2008, 4:22pm UTC](https://www.ruby-forum.com/t/getting-unexpected-string-value-for-null-values/145746/1 "2008-08-13T16:22:52Z")

</div>

Upgrading a legacy app from 1.x to 2.1…

The app has a Product model, and the Products migration contains:

```
  t.column :serial_no, :string, :default => :null

```

But if I create new, empty Product object like this in script/console:

> p = Product.new

The serial\_no field is a string with this value:

> p.serial\_no  
> =\> “— :null\n”

I would have expected nil instead of a string representation of null.  
This is causing a slew of tests to break.

Why is this happening in 2.1?

The app uses Postgresql 8.3, if that matters.

Thanks,  
Jeff

---

<div class="post-metadata">

**Author:** ![jeff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e19b73/32.png) [@jeff](https://www.ruby-forum.com/u/jeff)\
**Post date:** [August 13, 2008, 4:32pm UTC](https://www.ruby-forum.com/t/getting-unexpected-string-value-for-null-values/145746/2 "2008-08-13T16:32:16Z")

</div>

On Aug 13, 2008, at 10:21 AM, Jeff wrote:

> Upgrading a legacy app from 1.x to 2.1…
> 
> The app has a Product model, and the Products migration contains:
> 
> ```
> t.column :serial_no, :string, :default => :null
> 
> ```

You probably mean to have:

:default =\> nil

which is the same as not specifying a result.

> This is causing a slew of tests to break.  
> You have a symbol :null rather than nil or “null”. The YAML  
> serialization you see is a reasonable way to store a Ruby symbol in a  
> database.

> Why is this happening in 2.1?
> 
> The app uses Postgresql 8.3, if that matters.
> 
> Thanks,  
> Jeff

You’re welcome,  
-Rob

Rob B. [http://agileconsultingllc.com](http://agileconsultingllc.com)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![jeff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e19b73/32.png) [@jeff](https://www.ruby-forum.com/u/jeff)\
**Post date:** [August 13, 2008, 4:46pm UTC](https://www.ruby-forum.com/t/getting-unexpected-string-value-for-null-values/145746/3 "2008-08-13T16:46:57Z")

</div>

On Aug 13, 9:31 am, Rob B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> ```
> :default => nil
> 
> ```

Ugh… yes, thanks for spotting that. This is a legacy app that I  
didn’t write, but I guess I can simply write a new migration to change  
the column default.

Thanks!  
Jeff

REST with Rails  
Saturday, Oct 4, 2008  
Austin, TX  
[http://www.purpleworkshops.com/workshops/rest-and-web-services](http://www.purpleworkshops.com/workshops/rest-and-web-services)
