Home RailsAdmin: ActiveRecord::RecordNotUnique , inserts id when creating user #2972
Reply: 1

RailsAdmin: ActiveRecord::RecordNotUnique , inserts id when creating user #2972

applecrusher Published in 2017-12-29 21:02:52Z

I seem to be getting a problem when inserting into the users table. I am not sure why, but only that it is getting the current user's id (confirmed by seeding additional user. I know the solution would be to remove adding the id when adding users, but I don't know how and have been trying to find the right file for 30 minutes. I am using MYSQL. The error is below:

ActiveRecord::RecordNotUnique in RailsAdmin::MainController#new
Mysql2::Error: Duplicate entry '1' for key 'PRIMARY': INSERT INTO `users`

Any possible solution to this? I am willing to fix if someone just points me to the right file(s). Thanks!

Joaquin Roca
Joaquin Roca Reply to 2017-12-29 22:44:58Z

This is my first answer, so take this with many grains of salt. I've had similar issues in the past when I've messed around with the database directly in SQL and ignored callbacks in my models. Messes up the primary key sequence. Some version of resetting the primary key usually helped. Something like:


Should look something like: ActiveRecord::Base.connection.reset_pk_sequence!('users')

That might be for PostgreSQL, however. You might have to find a MySQL way to do it. Hope that helps!

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.301015 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO