Mrelation does not exists

Hello!

I'm having the following error:

RuntimeError: ERROR C42P01 Mrelation "subjects_users_id_seq" does not exist Fnamespace.c L200 RRangeVarGetRelid: SELECT currval('subjects_users_id_seq')

when I try to do:

subject= SubjectsUser.new(params[:subjects_user]) subject.save

The models:

class User < ActiveRecord::Base   has_one :last_entrie   has_one :address_book   has_and_belongs_to_many :subjects   has_one :user_detail   has_and_belongs_to_many :subjects end

class Subject < ActiveRecord::Base   has_and_belongs_to_many :users   belongs_to :subject_group end

class SubjectsUser < ActiveRecord::Base end

Thank you for your attention,

Paulo Abreu

You're using postgresql.

It uses a 'serial' field for each primary key. When it inserts a new row, it pulls the next 'id' value from something called a sequence (basically, a counter).

For some reason, the subjects_users_id_seq sequence isn't there any more.

You can recreate it - try '\h create sequence' from inside psql. If you have existing data in subjects_users, you need to make sure the sequence starts with a number 1 higher than the current highest value in the 'id' field of subjects_users.