I do registration with devise
Added username field for User. For authorization I use email + pwd.
class ApplicationController < ActionController::Base protect_from_forgery with: :exception before_action :configure_permitted_parameters, if: :devise_controller? protected def configure_permitted_parameters devise_parameter_sanitizer.permit(:sign_up, keys:[:username]) end end class User < ApplicationRecord validates :username, presence: true devise :database_authenticatable, :registerable, :rememberable, :trackable, :validatable end ActiveRecord::Schema.define(version: 20170228132910) do create_table "users", force: :cascade do |t| t.string "email", default: "", null: false t.string "encrypted_password", default: "", null: false t.string "username", default: "", null: false 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.datetime "created_at", null: false t.datetime "updated_at", null: false t.index ["email"], name: "index_users_on_email", unique: true t.index [nil], name: "index_users_on_reset_password_token", unique: true end end The first user registered normally, on the second I get an error
ActiveRecord :: RecordNotUnique in #Devise :: RegistrationsController # create SQLite3 :: ConstraintException: UNIQUE constraint failed: index ) VALUES (?,?,?,?,?)
What's wrong with index_users_on_reset_password_token?
Added migration
class DeviseCreateUsers < ActiveRecord::Migration[5.0] def change create_table :users do |t| ## Database authenticatable t.string :email, null: false, default: "" t.string :encrypted_password, null: false, default: "" # Registrable t.string :username, null: false, default: "" ## Rememberable t.datetime :remember_created_at ## Trackable 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.timestamps null: false end add_index :users, :email, unique: true add_index :users, :reset_password_token, unique: true end end
t.index [nil]- what? How did this come about? Show the migration that issued it. - D-sideintegeridwith auto increment. Rails uses this by default. - D-sidereset_password_token- vp_arth