2014-12-26 25 views
2

我試圖添加一個新的設計模型。當我使用sign_up路徑時,我可以創建一個用戶,但在保存新用戶(醫生)後會拋出一個錯誤。這個錯誤並不是很有幫助,所以我希望有人能指出我正確的方向進行調試。Rails Devise PG :: SyntaxError:ERROR:零長度分隔標識符位於或接近「」「」

的錯誤是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

我的模式是

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 

我應該在哪裏尋找調試呢?我試圖調試設備控制器,但我找不到它。

謝謝。

+0

生成的查詢' WHERE「醫生」。「」IS NULL「這是postgres中無效的語法。有關錯誤的說明,請參閱http://stackoverflow.com/questions/23165282/error-zero-length-delimited-identifier-at-or-near-line-1-delete-from-reg#comment35439475_23165282。 –

回答

6

你需要一個主鍵在表中,如果你不想使用id作爲主鍵,你可以在這樣的模型中的其他主鍵定義:

class Doctor < ActiveRecord::Base 
set_primary_key :email 
end 
+0

如果您使用rails 3.2+,不推薦使用'set_primary_key'。使用'self.primary_key =:email' – Penguin

相關問題