views:

401

answers:

5

Hi does anyone know what this means? I only get this error when I app is deployed on a server and using PostgresQL. When I'm running locally and testing on SQLite, it is fine. I have a features_simulations join table, I think it is related to it somehow.

Processing AdminController#confirmed (for 211.30.107.155 at 2009-03-25 09:06:21) [GET]
  Session ID: 59d7fdbbb6ec77367c310df0c0928a2a


ActiveRecord::StatementInvalid (PGError: ERROR:  relation "features_simulations_id_seq" does not exist
: SELECT currval('features_simulations_id_seq')):
    /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/connection_adapters/abstract_adapter.rb:188:in `log'
    /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/connection_adapters/postgresql_adapter.rb:503:in `execute'
    /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/connection_adapters/postgresql_adapter.rb:1000:in `select_raw'
    /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/connection_adapters/postgresql_adapter.rb:987:in `select'
    /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/connection_adapters/abstract/database_statements.rb:7:in `select_all_without_query_cache'
    /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/connection_adapters/abstract/query_cache.rb:60:in `select_all'
A: 

I'm not sure, but maybe you need id in features_simulations table. Id isn't needed if you use has_and_belongs_to_many relations. But I think for has_many :through, you need id column in your join table.

Try adding it in migration:

add_column :features_simulations, :id, :integer, :primary_key
klew
A: 

I think "features _simulations _id _seq" is a sequence that has to be created in the database. This sequence seems to be generating the id for the table.

Srividya Sharma
A: 

In Postgres you can use a serial type for an auto-incrementing field, which will automatically create the necessary sequence. You can use an integer type and manually create the sequence if you want, setting a default as the next value from the sequence.

Seems like the code is trying to find the current value of the sequence and failing because the sequence doesn't exist. I'm not sure if rails automatically creates the right type for Postgres primary keys.

dylanfm
+1  A: 

ActiveRecord doesn't really use compound keys. The joining tables still have to have an ID in them for atomic deletes and updates. I think everyone else has said the same thing but in a more roundabout way.

Ghoti
You can add support for CPK's by installing Dr.Nics composite primary keys, that will let do Model.find(1,2) and all it needs is set_primary_keys :field_x, :field_y. See http://compositekeys.rubyforge.org/ for more information
Omar Qureshi
A: 

Its a problem with the fixtures. Check your Fixture names against your table names. You will get this error if there is a mismatch between the two.

Shreyas Satish