本文介绍了Rails Devise PG :: SyntaxError:ERROR:零距离定界标识符在或接近“”“”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试添加一个新的设计模型。当我使用sign_up路径时,我可以创建一个用户,但是在保存新用户(医生)后会出现错误。错误不是很有帮助,所以我希望有人能指出正确的方向进行调试。



错误是 Devise :: RegistrationsController中的ActiveRecord :: StatementInvalid#create



PG :: SyntaxError:ERROR:零距离分隔符号在或附近1:... in_ip= $ 4,sign_in_count= $ 5 WHERE医生IS NULL ^:UPDATE医生SETcurrent_sign_in_at= $ 1,current_sign_in_ip= $ 2,last_sign_in_at= $ 3,last_sign_in_ip= $ 4,sign_in_count= $ 5 WHERE医生 IS NULL



我的模式是

  create_tabledoctors,id:false,force:true do | t | 
t.stringemail,默认值为,null:false
t.stringencrypted_pa​​ssword ,null:false
t.stringreset_password_token
t.datetimereset_password_sent_at
t.datetimeremember_created_at
t.integersign_in_count,默认值:0, null:false
t.datetimecurrent_sign_in_at
t.datetimelast_sign_in_在
t.stringcurrent_sign_in_ip
t.stringlast_sign_in_ip
end

add_index医生,[电子邮件],名称:index_doctors_on_email ,unique:true,using::btree
add_indexdoctors,[reset_password_token],name:index_doctors_on_reset_password_token,unique:true,using::btree
我应该在哪里寻找调试这个?/ / pre>

我试图调试设计控制器,但我找不到它。



谢谢。

解决方案

如果您不想使用id作为主键,则需要在表中使用主键,在模型中定义其他主键,如下所示:

  class Doctor< ActiveRecord :: Base 
set_primary_key:email
end


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.

解决方案

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

这篇关于Rails Devise PG :: SyntaxError:ERROR:零距离定界标识符在或接近“”“”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 08:13