I have taken over an existing Rails 3.2.9 app and am trying to set it up on my local windows 7 machine, but am getting the following error when trying to register a user:
ActiveRecord::StatementInvalid in Workers::RegistrationsController#create
PG::Error: ERROR: null value in column "id" violates not-null constraint DETAIL:
Failing row contains (null, 8f9f248b33a121ec83a38310, ZqddTnkfmB7Afu9Ukwcx, 0, null, null, null, null, null, 2014-11-25 17:55:43.8317, 2014-11-25 17:55:43.8317, null, dtest@gmail.com, null, null, null, null, null, null, null, null, null, null, null, pending, donnie, bertz, null, f, f, f, null, null, null, null, null, null, test.com, yEqp4FV5XCKS9xaRnnwz, null, 2014-11-25 17:55:43.8307, null, null, null, 0, null, null, Work, null, null, null, null, null, f, null, f, null, 0, 0, 0, null, f, 0, null, null, null, null, null). :
INSERT INTO "users" ("active", "keys", "address", "admin", "avail", "availof", "content_type", "file_name", "file_size", "a_updated_at", "calendar_json", "employees", "company_1", "company_2", "company_3", "confirmation_sent_at", "confirmation_token", "confirmed_at", "created_at", "current_sign_in_at", "current_sign_in_ip", "data", "domain", "email", "encrypted_password", "extra_links", "f1", "failed_attempts", "first_name", "fulltime", "general_help", "headline", "intro", "jobs_count", "keywords", "last_name", "last_request_at", "last_sign_in_at", "last_sign_in_ip", "l1", "locked_at", "metric_units", "opt_out", "password_salt", "phone", "credit", "rate", "rating_count", "receive_correspondence", "remember_created_at", "remember_token", "remote", "reset_password_sent_at", "reset_password_token", "sign_in_count", "avatar_url", "status", "time_zone", "t1", "type", "unconfirmed_email", "unlock_token", "updated_at", "used_credits", "video_url", "wizard_step", "zipcode") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28, $29, $30, $31, $32, $33, $34, $35, $36, $37, $38, $39, $40, $41, $42, $43, $44, $45, $46, $47, $48, $49, $50, $51, $52, $53, $54, $55, $56, $57, $58, $59, $60, $61, $62, $63, $64, $65, $66, $67) RETURNING "id"
Originally, I was getting an ActiveRecord::NotNullViolation error and the :id field was being included in the insert statement. To try to resolve that, I added self.primary_key = :id
to the user model. That removed :id from the insert, but I now notice that, while the insert statement looks ok in the error message, the 'failing row' actually has one extra column (68) and they are not in the same order as listed in the insert statement (which lists the columns alphabetically).
The application is utilizing devise and omniauth, if either of those would be relevant.
schema.rb:
create_table "users", :force => true do |t|
t.string "encrypted_password", :null => false
t.string "password_salt"
t.integer "sign_in_count", :default => 0, :null => false
t.datetime "last_request_at"
t.datetime "last_sign_in_at"
.
.
.
t.string "unconfirmed_email"
end
EDIT 1
SQL:
CREATE TABLE users (
id integer NOT NULL,
created_at timestamp without time zone,
updated_at timestamp without time zone,
encrypted_password character varying(255) NOT NULL,
password_salt character varying(255),
sign_in_count integer DEFAULT 0 NOT NULL,
last_request_at timestamp without time zone,
last_sign_in_at timestamp without time zone,
current_sign_in_at timestamp without time zone,
last_sign_in_ip character varying(255),
current_sign_in_ip character varying(255),
email character varying(255) NOT NULL,
.
.
.
reset_password_sent_at timestamp without time zone,
unconfirmed_email character varying(255),
data hstore
);
ALTER TABLE ONLY users
ADD CONSTRAINT users_pkey PRIMARY KEY (id);
I should also mention that the only instructions from the original developers were to manually create the Users table first, for ActiveAdmin issues.
EDIT 2 - the 'offending' code
class Employers::RegistrationsController < Devise::RegistrationsController
def create
super
session[:omniauth] = nil unless @employer.new_record?
end
private
def build_resource(*args)
super
if session[:omniauth]
@employer.apply_omniauth(session[:omniauth])
end
end
#Overwrite signin to make sure only users are signed in (for backward compatibility)
def sign_in(resource_or_scope, *args)
super(:user, *args)
end
end