So far, it\’s RoR

Ruby on Rails, PostgreSQL, SVN, etc….

“Multiple default values” migration error with PostgreSQL 8.2.5

Posted by Chirag Patel on December 16, 2007

PostgreSQL 8.2.5 error

== CreateHeartrates: migrating ================================================

— create_table(:heartrates)

NOTICE: CREATE TABLE will create implicit sequence “heartrates_id_seq” for serial column “heartrates.id”

rake aborted!

PGError: ERROR: multiple default values specified for column “id” of table “heartrates”

: CREATE TABLE heartrates (“id” serial primary key DEFAULT NULL, “user_id” integer DEFAULT NULL, “timestamp” timestamp with time zone DEFAULT NULL, “heartrate” smallint NOT NULL)

 

 

Solution

I don’t see the above error on my Lenovo Windows machine because it’s running PostgreSQL 8.2.4. The issue occurs with PostgreSQL 8.2.5

 

Add this to the create table migration

 

t.column :id, :primary_key, :null => false

 

 

This is probably the simplest way to deal with this defect.

 

 

Post from: Migrations and PostgreSQL Primary Keys) – Rails Trac – Trac:

I tried to find a good place to patch the code, but everywhere I did, I could easily imagine someone yelling, “you can’t touch that”!

 

For instance, if scheme_definitions.rb’s primary_key could set :null => false, then everyone should be happy, even other db’s. Except, that of course you change all db’s to ‘NOT NULL’ versus ‘DEFAULT NULL’. I don’t know why you’d want to say ‘DEFAULT NULL’ though, it seems vaguely wrong.

 

This seems to be still in rails 2.0 too, and is still in 1.2.6.

-Adam

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: