How do we do this in EOSIO multi_index table? Want to define a table with an auto increment primary key id.


Have a look to available_primary_key in the EOS documentation, multi indexes do support auto increment keys.

  • Please update the link, current one is not working. – USMAN FAZIL Jan 14 at 20:27

You check the way monstereos did. They have table st_pet_config define last_id start with 0 and everytime you create new pet last_id increase https://github.com/leordev/monstereos/blob/master/contracts/pet/pet.hpp#L85

  • Doing it this way is obsolete. – cmadh Apr 7 '19 at 16:15

The two answers to this question are links to external sites that are now broken. this is why answers that are links are frowned upon, links break and therefore your answer breaks. to actually auto increment the primary key say your multi index uses a uint64_t as its id. When emplacing into the table set the id like so.

row.column_name = table_name.available_primary_key();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.