Rails Devise PG::SyntaxError: ERROR: zero-length d

2019-05-28 15:44发布

问题:

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.

回答1:

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