1

I have existing rails app that have some tables with some data. I did the CRUD operation directly from postgresql client before using activeadmin.

I don't know whether I missed the documentation or this is a bug: activeadmin cannot detect my existing autoincrement id for table.

enter image description here

If I refresh the submitted form until the auto increment id surpass the existing id in my table, it works.

1 Answer 1

2

First think which I could think of would be that you have passed the id parameter in permit params. Please check that and if is present then remove it.

Secondly,as mentioned in the post that there are already data in the database so there is a problem with the sequences generated, since they can be only used once.

The solution is to set the sequence for your song_artists.id column to the highest value in the table with a query like this:

SELECT setval('song_artist_id_seq', (SELECT max(id) FROM song_artists));

I am assuming that your sequence name "song_artist_id_seq", table name "song_artist", and column name "id".

To get the sequence name run the below mentioned command:

SELECT pg_get_serial_sequence('tablename', 'columname'); 

For Resetting the postgres sequences from rails console:

ActiveRecord::Base.connection.tables.each do |t|
 ActiveRecord::Base.connection.reset_pk_sequence!(t)
end

Another solution would be to override the save() method in your song_artist class to manually set the song_artist id for new records but is not advisable.

Sign up to request clarification or add additional context in comments.

3 Comments

I don't pass the id parameter in the permit params. It's just permit_params :album_id, :song_id, :artist_id, :primary I use postgresql client to do CRUD operation before integrating activeadmin. Is that possibly the cause?
what is primary in permit params?
It's boolean to indicate artist contribution on an album

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.