directus icon indicating copy to clipboard operation
directus copied to clipboard

Reset sequence value after file-based import

Open eliteproxy7 opened this issue 4 years ago • 8 comments

adding a new item on a collection, get the following error

There were validation errors for the following hidden fields: id: Value has to be unique

Version: Directus v9.0.0-rc.76

this seemed to have started after I updated some items with the new import from file method but I am not sure.

eliteproxy7 avatar Jun 16 '21 18:06 eliteproxy7

this seemed to have started after I updated some items with the new import from file method but I am not sure.

Ah that would make sense actually. Those creations will save the primary keys included in the CSV, but that won't reset the sequence used in the database.

What database are you using?

rijkvanzanten avatar Jun 17 '21 15:06 rijkvanzanten

Postgres 13

eliteproxy7 avatar Jun 17 '21 15:06 eliteproxy7

for anyone looking how to reset this on the DB side

  1. run this query SELECT MAX(id) FROM your_table;
  2. SELECT nextval('your_table_id_seq'); mine was [your_table]_id_seq
  3. if the Valu from step 2 is not greater then the value form step1 then go to step 4
  4. run this query SELECT setval('your_table_id_seq',(SELECT GREATEST(MAX(your_id)+1,nextval('your_table_id_seq'))-1 FROM your_table)) "your_id" is the value from step 1

eliteproxy7 avatar Jun 28 '21 04:06 eliteproxy7

Only with Postgres 13?

rashidpathiyil avatar Jun 05 '22 08:06 rashidpathiyil

Only with Postgres 13?

The above shared sql query is for postgres, yeah

rijkvanzanten avatar Jun 06 '22 18:06 rijkvanzanten

Linear: ENG-294

rijkvanzanten avatar Dec 15 '22 22:12 rijkvanzanten

Any ETA on this?

florian-lefebvre avatar Feb 15 '23 18:02 florian-lefebvre

Any ETA on this?

Unfortunately, we can not provide estimates on features or fixes. As of now, the only way to get an accurate timeline or release date is to sponsor this task. We recognize that this may be an important feature/fix, but we are a small open-source organization with a lot to triage and complete. If you can't sponsor this ticket, then the next best thing is to increase its priority by giving it a 👍

rijkvanzanten avatar Feb 15 '23 19:02 rijkvanzanten