Forum: Ruby on Rails :primary_key in create_table with postgresql seems broken

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
3f38541776a2513a20ea2f1c2d522cb3?d=identicon&s=25 Perry Smith (pedz)
on 2007-07-14 15:12
My model has:

class CreateSamples < ActiveRecord::Migration
  def self.up
    create_table :samples, :primary_key => :other_id do |t|
      t.column :name, :string

  def self.down
    drop_table :samples

my unit test has:

require File.dirname(__FILE__) + '/../test_helper'

class SampleTest < Test::Unit::TestCase

  # Replace this with your real tests.
  def test_save
    sample =

It fails.

If I get into script/console, the "keys" include the primary key but I
believe it should not:

>> sample =
sample =
=> #<Sample other_id: nil, name: nil>
>> puts sample.attributes.keys
puts sample.attributes.keys
=> nil

The error from the test is:

  1) Error:
ActiveRecord::StatementInvalid: PGError: ERROR:  null value in column
"other_id" violates not-null constraint
: INSERT INTO samples ("name", "other_id") VALUES(NULL, NULL)

Notice that other_id is being specified in the insert instead of just
letting it default to the auto sequence.

Is this going to be a problem in the postgresql adapter?  I'd like to
track this down but so far, I'm not getting anywhere.
This topic is locked and can not be replied to.