简体   繁体   中英

rails devise id generator

i have a rails web app with a postgress database, im using devise for user signup and signin. i changed from one db to a new db, and moved my old users to the new db. the old users are able to sign in, but new users cant sign up. when a new users signup, devise sends them to users path, am not getting an error. other than '500 server error' no new users are registered. im able to create new users, when i delete the whole db and create a new users manually. So that lets me know, where my issue is, i think its a user id sequence issue.
how do i fix this issue, to allow new users to be able to sign up, and keep my old users data

HERES MY ERROR.

ActiveRecord::RecordNotUnique (PG::UniqueViolation: ERROR:  duplicate key value violates unique constraint "users_pkey"
DETAIL:  Key (id)=(2) already exists.

When you moved your users from one db to the other you probably didn't update the id sequence

Try this in the psql console, you can open it easily by entering rails db while inside your project. It will find out the last ID for the users table and then set the sequence to the next value.

SELECT setval('users_id_seq', COALESCE((SELECT MAX(id)+1 FROM users), 1), false);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM