# Data migration of date constant

**URL:** <https://www.ruby-forum.com/t/data-migration-of-date-constant/81530>\
**Category:** Rails\
**Created:** [January 9, 2007, 6:45pm UTC](https://www.ruby-forum.com/t/data-migration-of-date-constant/81530 "2007-01-09T18:45:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![byrnejb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d2c977/32.png) [@byrnejb](https://www.ruby-forum.com/u/byrnejb)\
**Post date:** [January 9, 2007, 6:45pm UTC](https://www.ruby-forum.com/t/data-migration-of-date-constant/81530/1 "2007-01-09T18:45:49Z")

</div>

A simple question: what is the correct way to input a fixed string as a  
datetime field within a rails data migration?

I tried this:

…  
:record\_effective\_from =\> ‘20020731000000’,  
…

And got this:

# == AddEntityTestData: migrating

rake aborted!  
RuntimeError: ERROR C42804 Mcolumn “record\_effective\_from” is of  
type timestamp without time zone but expression is of type bigint HYou  
will need to rewrite or cast the expression.

Soooo… how do I rewrite or recast this to work?

Regards,

---

<div class="post-metadata">

**Author:** ![byrnejb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d2c977/32.png) [@byrnejb](https://www.ruby-forum.com/u/byrnejb)\
**Post date:** [January 9, 2007, 8:38pm UTC](https://www.ruby-forum.com/t/data-migration-of-date-constant/81530/2 "2007-01-09T20:38:33Z")

</div>

James B. wrote:

> Soooo… how do I rewrite or recast this to work?
> 
> Regards,

Enclose the date in single or double quotes. Ok, I got that to work.  
Next question.

I have to load historical data and some of the dates are pre-1900. How  
do I get rails / ruby / postgresql to handle this. As of now when I do  
this:

…  
:record\_effective\_from =\> ‘\<%= DateTime.parse(“18920801000000”)  
%\>’,  
…

or this:

…  
:record\_effective\_from =\> ‘18920801000000’,  
…

both yield this on the database:

1901-12-13 15:45:52

The OS is CentOS-4.4 with ruby 1.8.4 (2005-12-24) [i386-linux] and rails  
(1.1.6.5848) (1.2RC1)

---

<div class="post-metadata">

**Author:** ![byrnejb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d2c977/32.png) [@byrnejb](https://www.ruby-forum.com/u/byrnejb)\
**Post date:** [January 9, 2007, 9:06pm UTC](https://www.ruby-forum.com/t/data-migration-of-date-constant/81530/3 "2007-01-09T21:06:08Z")

</div>

James B. wrote:

> The OS is CentOS-4.4 with ruby 1.8.4 (2005-12-24) [i386-linux] and rails  
> (1.1.6.5848) (1.2RC1) and postgres-pr (0.4.0)

I have another problem with data migrations. I have added two fields to  
the subject table that are called “changed\_on” and “created-on”  
repectively. These are supposed to default to the current time according  
to my understanding of the Rails conventions and therefore I have not  
named them in the data migration. However, when I run rake db:migrate I  
get this:

# \*\* Invoke db:migrate (first\_time) \*\* Invoke environment (first\_time) \*\* Execute environment \*\* Execute db:migrate == CreateEntities: migrating

– create\_table(:entities)  
rake aborted!  
RuntimeError: ERROR C0A000 Mdate/time value “current” is no longer  
supported Fdatetime.c L1369 RDecodeDateTime: CREATE TABLE  
entities (“id” serial primary key, “entity\_ident” bigint NOT NULL,  
“entity\_name” character varying(40) NOT NULL, “entity\_legal\_style”  
character varying(255) NOT NULL, “entity\_type” character varying(4) NOT  
NULL, “effective\_from” timestamp NOT NULL, “superceded\_after” timestamp,  
“created\_by” character varying(255) NOT NULL, “created\_on” timestamp  
DEFAULT ‘CURRENT\_TIMESTAMP’, “changed\_by” character varying(255) NOT  
NULL, “changed\_on” timestamp DEFAULT ‘CURRENT\_TIMESTAMP’)  
/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4.5848/lib/active\_record/connection\_adapters/abstract\_adapter.rb:128:in  
`log' /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4.5848/lib/active_record/connection_adapters/postgresql_adapter.rb:152:in`execute’  
/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4.5848/lib/active\_record/connection\_adapters/abstract/schema\_statements.rb:104:in  
`create_table' /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4.5848/lib/active_record/migration.rb:275:in`method\_missing’  
/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4.5848/lib/active\_record/migration.rb:259:in  
`say_with_time' /usr/lib/ruby/1.8/benchmark.rb:293:in`measure’  
/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4.5848/lib/active\_record/migration.rb:259:in  
`say_with_time' /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4.5848/lib/active_record/migration.rb:273:in`method\_missing’  
./db/migrate//001\_create\_entities.rb:3:in `real_up' /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4.5848/lib/active_record/migration.rb:212:in`migrate’  
/usr/lib/ruby/1.8/benchmark.rb:293:in `measure' /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4.5848/lib/active_record/migration.rb:212:in`migrate’  
/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4.5848/lib/active\_record/migration.rb:335:in  
`migrate' /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4.5848/lib/active_record/migration.rb:330:in`migrate’  
/usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4.5848/lib/active\_record/migration.rb:297:in  
`up' /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4.5848/lib/active_record/migration.rb:288:in`migrate’  
/usr/lib/ruby/gems/1.8/gems/rails-1.1.6.5848/lib/tasks/databases.rake:4  
/usr/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:387:in `execute' /usr/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:387:in`execute’  
/usr/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:357:in `invoke' /usr/lib/ruby/1.8/thread.rb:135:in`synchronize’  
/usr/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:350:in `invoke' /usr/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:1906:in`run’  
/usr/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:1906:in `run’  
/usr/lib/ruby/gems/1.8/gems/rake-0.7.1/bin/rake:7  
/usr/bin/rake:18

Does this mean that the adapter I am using is broken or is something  
else amiss?

Regards,

---

<div class="post-metadata">

**Author:** ![byrnejb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d2c977/32.png) [@byrnejb](https://www.ruby-forum.com/u/byrnejb)\
**Post date:** [January 9, 2007, 9:55pm UTC](https://www.ruby-forum.com/t/data-migration-of-date-constant/81530/4 "2007-01-09T21:55:14Z")

</div>

Further to my last post, I replace postgres-pr with ruby-postgres and  
tried again. the error now says:

rake aborted!  
PGError: ERROR: date/time value “current” is no longer supported  
: CREATE TABLE entities (“id” serial primary key, “entity\_ident” bigint  
NOT NULL, “entity\_name” character varying(40) NOT NULL,  
“entity\_legal\_style” character varying(255) NOT NULL, “entity\_type”  
character varying(4) NOT NULL, “effective\_from” timestamp NOT NULL,  
“superceded\_after” timestamp, “created\_by” character varying(255) NOT  
NULL, “created\_on” timestamp DEFAULT ‘CURRENT\_TIMESTAMP’, “changed\_by”  
character varying(255) NOT NULL, “changed\_on” timestamp DEFAULT  
‘CURRENT\_TIMESTAMP’)

This looks to me like it is a PostgreSQL issue but what is providing  
Postgres with the date/time value of “current” (which was depreciated as  
of PostgreSQl 7.2)
