新手问题 Devise 注册用户 RecordNotUnique 错误

autumnwolf · 2016年08月30日 · 最后由 autumnwolf 回复于 2016年08月30日 · 2081 次阅读

我在用 Devise 注册一个用户:

curl -v -H "Accept: application/json" -H "Content-type: application/json" -X POST -d ' {"user":{"first_name":"firstname","last_name":"lastname","email":"[email protected]","password":"app123","password_confirmation":"app123","provider":"email"}}'  http://localhost:3000/users

得到错误:

"status":500,"error":"Internal Server Error","exception":"#\u003cActiveRecord::RecordNotUnique: Mysql2::Error: Duplicate entry 'email' for key 'index_users_on_uid_and_provider': INSERT INTO `users` (`encrypted_password`, `email`, `created_at`, `updated_at`, `authentication_token`) 

这个错误我目前理解像是 index_users_on_uid_and_provider 字段被设置了 email 的值,然后 email 数据库中已经有 email 这个值了。但是及时数据库中没有数据也是这个错误。 求大神指点下!

EDIT: 删除了

.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree
    t.index ["uid", "provider"], name: "index_users_on_uid_and_provider", unique: true, using: :btree

不过目前遇到错误:

{"status":406,"error":"Not Acceptable","exception":"#\u003cActionController::UnknownFormat: ActionController::UnknownFormat\u003e","traces":{"Application Trace":[],"Framework Trace":[{"id":0,"trace":"responders (2.3.0) lib/action_controller/respond_with.rb:207:in `respond_with'"},{"id":1,"trace":"devise (4.2.0) app/controllers/devise/registrations_controller.rb:32:in `create'"},{"id"

schema.rb

create_table "users", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
    t.string   "provider",                             default: "email", null: false
    t.string   "uid",                                  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"
    t.string   "confirmation_token"
    t.datetime "confirmed_at"
    t.datetime "confirmation_sent_at"
    t.string   "unconfirmed_email"
    t.string   "name"
    t.string   "nickname"
    t.string   "image"
    t.string   "email"
    t.text     "tokens",                 limit: 65535
    t.datetime "created_at",                                             null: false
    t.datetime "updated_at",                                             null: false
    t.string   "authentication_token",   limit: 30
    t.index ["authentication_token"], name: "index_users_on_authentication_token", unique: true, using: :btree
    t.index ["email"], name: "index_users_on_email", using: :btree

t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :tree t.index ["uid", "provider"], name: "index_users_on_uid_and_provider", unique: true, using: :tree

end

uid 中好像没有值

#1 楼 @awking 谢谢解决了 删除了 index 和 uid 字段 406 是默认不返回 json 数据!

需要 登录 后方可回复, 如果你还没有账号请 注册新账号