# Default Date storage 0000-00-00?

**URL:** <https://www.ruby-forum.com/t/default-date-storage-0000-00-00/65508>\
**Category:** Rails\
**Created:** [August 18, 2006, 8:30pm UTC](https://www.ruby-forum.com/t/default-date-storage-0000-00-00/65508 "2006-08-18T20:30:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chris\_Edie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e95f7d/32.png) [@Chris\_Edie](https://www.ruby-forum.com/u/Chris_Edie)\
**Post date:** [August 18, 2006, 8:30pm UTC](https://www.ruby-forum.com/t/default-date-storage-0000-00-00/65508/1 "2006-08-18T20:30:03Z")

</div>

So I have a database of orders more or less.(it is currently in the  
process of being upgraded to mysql with a rails fronted, from OLD  
Paradox database) On one page I made a ‘create new order’ system. This  
allows me to put in the due date and other info. However I wanted to put  
in the default value of ‘0000-00-00’ for the shipped date, as it hasn’t  
shipped yet. Only Ruby won’t let me do that, it calls that value ‘null’  
and balks saying  
“Mysql::Error: Column ‘Ship\_Date’ cannot be null…”  
It is probably something obvious I am just overlooking. But Its been one  
of those fridays and my mind is gone. So any help would be greatly  
appreciated.

---

<div class="post-metadata">

**Author:** ![Chris\_Edie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e95f7d/32.png) [@Chris\_Edie](https://www.ruby-forum.com/u/Chris_Edie)\
**Post date:** [August 18, 2006, 8:45pm UTC](https://www.ruby-forum.com/t/default-date-storage-0000-00-00/65508/2 "2006-08-18T20:45:13Z")

</div>

Hey Chris,

I ran into a similar problem with some legacy db tables and posted a  
message on this list. The only answer I got was “thats bad db  
design” which isn’t that helpful. You may be able to setup a  
“before\_save” callback to insert the default value manually or alter  
the table to allow nulls.

Hope that helps!  
Tim

---

<div class="post-metadata">

**Author:** ![Chris\_Edie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e95f7d/32.png) [@Chris\_Edie](https://www.ruby-forum.com/u/Chris_Edie)\
**Post date:** [August 18, 2006, 8:48pm UTC](https://www.ruby-forum.com/t/default-date-storage-0000-00-00/65508/3 "2006-08-18T20:48:14Z")

</div>

On Friday 18 August 2006 19:30, Chris Edie wrote:

> appreciated.  
> Chris,

Since the Ship Date can be null (i.e. it will have an unknown value),  
then you  
need to define the column in the table to be nullable.

If you are using migrations the default behaviour is to make a column  
nullable  
(to make it “not null” you need to specify :null =\> false). So I’m  
assuming  
you’ve created the database using SQL directly. Take the “NOT NULL”  
off the  
definition from that column.

You should never use default dates like 0000-00-00 or 9999-01-01 to  
signify an  
unknown date : this is what the null option on a database is there for.

HTH

Phil

---

<div class="post-metadata">

**Author:** ![Chris\_Edie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e95f7d/32.png) [@Chris\_Edie](https://www.ruby-forum.com/u/Chris_Edie)\
**Post date:** [August 18, 2006, 8:58pm UTC](https://www.ruby-forum.com/t/default-date-storage-0000-00-00/65508/4 "2006-08-18T20:58:58Z")

</div>

An amazingly simple solution… GAH! … really part of the problem with  
trying to bring a 15year old piece of software up to date, is I get  
myself caught in trying to keep it as similar as possible, while makeing  
the necessary changes.

I did go ahead and change the default values of the ship date to null.  
That seems to have worked well. I will have to go back in and edit some  
of the ‘reporting’ software that shows what hasn’t shipped yet to search  
for NULL instead of 0000-00-00 But hey. We are getting somewhere!  
Thanks you two for your help.  
-Chris

---

<div class="post-metadata">

**Author:** ![Chris\_Edie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e95f7d/32.png) [@Chris\_Edie](https://www.ruby-forum.com/u/Chris_Edie)\
**Post date:** [August 18, 2006, 9:09pm UTC](https://www.ruby-forum.com/t/default-date-storage-0000-00-00/65508/5 "2006-08-18T21:09:16Z")

</div>

On 8/18/06, Tim McIntyre [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hey Chris,
> 
> I ran into a similar problem with some legacy db tables and posted a  
> message on this list. The only answer I got was “thats bad db  
> design” which isn’t that helpful. You may be able to setup a  
> “before\_save” callback to insert the default value manually or alter  
> the table to allow nulls.

The problem with this particular issue is that most consider that  
behavior broken, not just bad design. If end users come up with a  
workarround instead of fixing the underlying issue that’s fine, but it  
should not be in rails core.
