Rails Devise PG::SyntaxError: ERROR: zero-length delimited identifier at or near “”“”

匿名 (未验证) 提交于 2019-12-03 01:34:02

问题:

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 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!