# How to make string column with null default?

**URL:** <https://discuss.rubyonrails.org/t/how-to-make-string-column-with-null-default/17879>\
**Category:** rubyonrails-talk\
**Created:** [September 7, 2007, 7:37am UTC](https://discuss.rubyonrails.org/t/how-to-make-string-column-with-null-default/17879 "2007-09-07T07:37:50Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Steven](https://avatars.discourse-cdn.com/v4/letter/s/94ad74/32.png) [@Steven](https://discuss.rubyonrails.org/u/Steven)\
**Post date:** [September 7, 2007, 7:37am UTC](https://discuss.rubyonrails.org/t/how-to-make-string-column-with-null-default/17879/1 "2007-09-07T07:37:50Z")

</div>

Hi,

I'm trying to use migrations to create a table with a string column that has a default value of null. Instead of a default of null, though, it's using the four-character string "NULL".

I found some similar bug reports (e.g., [http://dev.rubyonrails.org/ticket/9469](http://dev.rubyonrails.org/ticket/9469)[http://dev.rubyonrails.org/ticket/9145](http://dev.rubyonrails.org/ticket/9145) ), but that second one was closed with "cannot reproduce/works for me", so I must be doing something wrong???

This is what I'm doing. I tried this with gem rails 1.2.3 and edge rails 7416, and they both did the same thing.

$ rails project ; cd project $ cat \> config/database.yml &nbsp;&nbsp;&nbsp;development: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;adapter: sqlite3 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;database: db/project.development ^D $ mkdir db/migrate ; cat \> db/migrate/001\_initial\_schema.rb &nbsp;&nbsp;&nbsp;class InitialSchema \< ActiveRecord::Migration &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;def self.up &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;create\_table :items do |t| &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;t.column :name, :string &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# I also tried: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# t.column :name, :string, :null =\> true, :default =\> nil &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;&nbsp;end ^D $ cat \> app/models/item.rb &nbsp;&nbsp;&nbsp;class Item \< ActiveRecord::Base &nbsp;&nbsp;&nbsp;end ^D $ rake db:migrate

$ script/console Loading development environment.

> > x = Item.create

=\> #\<Item id: 1, name: "NULL"\>

> > x.name.length

=\> 4 ^D

$ sqlite3 db/project.development

> .schema items

CREATE TABLE items ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255) DEFAULT NULL);

> insert into items values (69, null); select \* from items;

1|NULL 69|

Thanks for you help, Steven
