4

I'm trying to add a new devise model. When I use the sign_up path I'm able to create a user but throws an error after the new user (doctor) is saved. The error isn't very helpful so I'm hoping someone could point me in the right direction for debugging.

The error is ActiveRecord::StatementInvalid in Devise::RegistrationsController#create

PG::SyntaxError: ERROR: zero-length delimited identifier at or near """" LINE 1: ...in_ip" = $4, "sign_in_count" = $5 WHERE "doctors"."" IS NULL ^ : UPDATE "doctors" SET "current_sign_in_at" = $1, "current_sign_in_ip" = $2, "last_sign_in_at" = $3, "last_sign_in_ip" = $4, "sign_in_count" = $5 WHERE "doctors"."" IS NULL

My schema is

create_table "doctors", id: false, force: true do |t|
    t.string   "email",                  default: "", null: false
    t.string   "encrypted_password",     default: "", null: false
    t.string   "reset_password_token"
    t.datetime "reset_password_sent_at"
    t.datetime "remember_created_at"
    t.integer  "sign_in_count",          default: 0,  null: false
    t.datetime "current_sign_in_at"
    t.datetime "last_sign_in_at"
    t.string   "current_sign_in_ip"
    t.string   "last_sign_in_ip"
  end

  add_index "doctors", ["email"], name: "index_doctors_on_email", unique: true, using: :btree
  add_index "doctors", ["reset_password_token"], name: "index_doctors_on_reset_password_token", unique: true, using: :btree

where should I be looking to debug this? I'm trying to debug the devise controller but I can't find it.

Thanks.

user2954587
  • 4,661
  • 6
  • 43
  • 101
  • The generated query has `WHERE "doctors"."" IS NULL` which is invalid syntax in postgres. See http://stackoverflow.com/questions/23165282/error-zero-length-delimited-identifier-at-or-near-line-1-delete-from-reg#comment35439475_23165282 for explanation about the error. – Prakash Murthy Dec 26 '14 at 17:34

1 Answers1

12

You need a primary key in your table, if you don't want to use an id as primary key, you can define in the model other primary key like this:

class Doctor < ActiveRecord::Base 
set_primary_key :email
end
chiwangc
  • 3,566
  • 16
  • 26
  • 32
Josito
  • 374
  • 2
  • 9