嗨,我很難找出這個錯誤。昨天我發佈了一個question,我的AcitveAdmin郵件字段總是空的。今天我也意識到問題有點大。Rails 4.2 ActiveAdmin 1.0.0.pre2由於重複鍵值違反唯一約束,無法創建AdminUser「index_admin_users_on_email
當我嘗試在軌添加一個新用戶控制檯將出現以下情況。
>> au = AdminUser.new(email: '[email protected]', password: "123456789", password_confirmation: "123456789")
=> #<AdminUser id: nil, email: "", encrypted_password: "$2a$10$Xt6EpJhtQ3d1v62KNZFUk.oi1RYe2gEBBeWVd/vApvi...",reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 0, current_sign_in_at: nil, last_sign_in_at: nil, current_sign_in_ip: nil, last_sign_in_ip: nil, created_at: nil, updated_at: nil>
>> au.valid?
AdminUser Exists (0.8ms) SELECT 1 AS one FROM "admin_users" WHERE"admin_users"."email" = '[email protected]' LIMIT 1
=> true
>> au.save
(0.8ms) BEGIN
AdminUser Exists (1.1ms) SELECT 1 AS one FROM "admin_users" WHERE "admin_users"."email" = '[email protected]' LIMIT 1
SQL (3.5ms) INSERT INTO "admin_users" ("encrypted_password","created_at", "updated_at") VALUES ($1, $2, $3) RETURNING "id" [["encrypted_password","$2a$10$Xt6EpJhtQ3d1v62KNZFUk.oi1RYe2gEBBeWVd/vApviETIlUvpQ2q"],
["created_at", "2015-10-21 13:57:44.081780"],["updated_at", "2015-10-21 13:57:44.081780"]]
PG::UniqueViolation: ERROR: duplicate key value violates unique constraint "index_admin_users_on_email"
DETAIL: Key (email)=() already exists.
: INSERT INTO "admin_users" ("encrypted_password", "created_at","updated_at") VALUES ($1, $2, $3) RETURNING "id"
(1.2ms) ROLLBACK
ActiveRecord::RecordNotUnique: PG::UniqueViolation: ERROR: duplicate key value violates unique constraint "index_admin_users_on_email"DETAIL: Key (email)=() already exists.
但我從來沒有使用過這個電子郵件。我最近分區我的數據庫系統,所以現在在生產環境中我使用了不同的數據庫,但是對於開發everythi ng保持不變。 admin_users
表中的一個AdminUser仍然可以訪問,我可以通過ActiveAdmin儀表板使用此登錄。
我在這裏發現了similar問題,但解決方案對我無效。 有沒有人有任何建議?感謝所有提前!
更新
原來有一個空地址的管理用戶。所以這就是爲什麼我有dublicate電子郵件字段。我摧毀了那個用戶。現在我可以添加另一個管理員。但電子郵件字段仍未寫入。
>> au = AdminUser.new(email: '[email protected]', password: "123456789", password_confirmation: "123456789")
=> #<AdminUser id: nil, email: "", encrypted_password: "$2a$10$TWpMSdAxPl4vTFg54XvZcOe5Xkc7t4mf2Or7UlbkoA8...", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 0, current_sign_in_at: nil, last_sign_in_at: nil, current_sign_in_ip: nil, last_sign_in_ip: nil, created_at: nil, updated_at: nil>
>> au.valid?
AdminUser Exists (25.6ms) SELECT 1 AS one FROM "admin_users" WHERE "admin_users"."email" = '[email protected]' LIMIT 1
=> true
>> au.save
(0.7ms) BEGIN
AdminUser Exists (0.8ms) SELECT 1 AS one FROM "admin_users" WHERE "admin_users"."email" = '[email protected]' LIMIT 1
SQL (61.7ms) INSERT INTO "admin_users" ("encrypted_password",
"created_at", "updated_at") VALUES ($1, $2, $3) RETURNING "id"
[["encrypted_password",
"$2a$10$TWpMSdAxPl4vTFg54XvZcOe5Xkc7t4mf2Or7UlbkoA8W/n3rOGGwC"],
["created_at", "2015-10-21 14:28:46.750437"], ["updated_at","2015-10-2114:28:46.750437"]]
(18.0ms) COMMIT
=> true
我也降級到ActiveAdmin 1.0.0.pre1,但問題仍然存在。
控制檯中ActiveUser.all的結果是什麼?插入語句isn'爲電子郵件插入一個值...因此,如果有一個用戶在那裏有一個NULL電子郵件地址,這就是爲什麼你首先得到重複的錯誤,而不是一個NOT NULL違反錯誤。你也可以發佈你使用的ActiveAdmin版本嗎? – wspurgin
真的有一個空郵件地址的用戶。我摧毀了這一個。現在我可以保存一個新的管理員用戶,但是當我使用AdminUser.all時,電子郵件地址顯示爲「email:」「''。我將更新整個輸出的問題 – theDrifter
而且我直接從github使用ActiveAdmin1.0.0.pre2 – theDrifter