Unique ID tc_devices

Cris Amende2 years ago

Dears,

After a server re-install we installed the latest version of traccar, and used a db backup to put back all of the devices, groups,users etc etc.
In the tc_devices table, there are several gaps in the primary key (ID) field, obviously due to previously deleted devices.
We now have a challenge that somehow when we're adding a new device traccar tries to use a unique id that is already in use. (currently on number 19) Any time we try to add a new device it moves up one number, untill it reaches a gap in the data, i.e. assigns it a number that was previously deleted.

We could manually manipulate the current device id's to be in sequential order again, not sure if that would affect other functions of the system.
Or is there a way to manipulate the "Start" number on which traccar tries to assign a new device, i.e. start from ID = 1000 or something ?

Thanks to let me know.

Anton Tananaev2 years ago

It is possible to change the start number. Read about auto increment in your database.

This is for MySQL:

https://dev.mysql.com/doc/refman/8.0/en/example-auto-increment.html

Cris Amende2 years ago

Thanks, we're working with postgresql, so it was slightly different, but your confirmation helped greatly in getting to the solution.

For those also experiencing this problem and using postgresql.
Running a query per below will solve the issue:
alter sequence tc_devices_id_seq restart with XXX

(Replace XXX with a number greater then the highest current ID in your tc_devices table)

Obviously replace tc_devices_id_seq with tc_users_id_seq when this problem occurs on the users table...