Perry Smith
2007-Jul-14 13:12 UTC
:primary_key in create_table with postgresql seems broken
My model has: class CreateSamples < ActiveRecord::Migration def self.up create_table :samples, :primary_key => :other_id do |t| t.column :name, :string end end def self.down drop_table :samples end end 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 = Sample.new sample.save end end It fails. If I get into script/console, the "keys" include the primary key but I believe it should not:>> sample = Sample.newsample = Sample.new => #<Sample other_id: nil, name: nil>>> puts sample.attributes.keysputs sample.attributes.keys name other_id => nil The error from the test is: 1) Error: test_save(SampleTest): ActiveRecord::StatementInvalid: PGError: ERROR: null value in column "other_id" violates not-null constraint : INSERT INTO samples ("name", "other_id") VALUES(NULL, NULL) /Users/pedz/rails-projects/pk/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:135:in `log'' /Users/pedz/rails-projects/pk/vendor/rails/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb:160:in `execute'' 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. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---