Home>

I'm making an EC site with Rails.
The following error message occurred when trying to edit a column in the user table.

** ActiveRecord :: RecordNotUnique in RailsAdmin :: MainController # edit **
SQLite3 :: ConstraintException: UNIQUE constraint failed: users.unlock_token: UPDATE "users" SET "current_sign_in_at" =?, "Last_sign_in_at" =?, "Confirmed_at" =?, "Confirmation_sent_at" =?, "Unconfirmed_email" =?, "Unlock_token "=?," provider "=?," uid "=?," username "=?," admin_flg "=?," point "=?," updated_at "=? WHERE" users "." id "=?

I can't figure out which area is suspicious, and I don't know which part of the code should be written. .
Can anyone please professor? Thank you. . .

  • Answer # 1

    I think the

    users table'sunlock_tokencolumn has a unique constraint. If a unique constraint is attached, you cannot create multiple records with the same value.

    You can check the list of registeredunlock_tokenwith the following SQL.

    SELECT unlock_token FROM users;

    You probably already have a record with the value you are trying to update with an UPDATE statement, and that is the cause of the error. For your information.