Resetting autoincrement and truncate with cascade
See original GitHub issueDoes knex provide any abstracted way of resetting autoincrement for a table? From what I can tell it can only be done using knex.raw()
which makes it dependent on the dialect used.
A .resetIncrements()
call would be nice so that it can be chained with .del()
as knex('table_name').del().resetIncrements()
which effectively resets a table to the state it was in when migrations were run.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:21 (6 by maintainers)
Top Results From Across the Web
PostgreSQL - Truncate a table on cascade and reset all ...
It work only for one sequence, but my problem is to restart all the sequence of the truncated tables. Consider when I use...
Read more >Reset auto increment counter in postgres - sql - Stack Overflow
The following command does this automatically for you: This will also delete all the data in the table. So be careful. TRUNCATE TABLE...
Read more >Reset Auto-Increment IDs in Postgres - Brian Childress
Sometimes that data is in a table with an auto-incrementing ID and I use the TRUNCATE command to remove all data and reset...
Read more >Truncate a table and restart Sequences (Identity and cascade ...
But the above command doesn't restart the sequences i.e; IDENTITY and CASCADE associated with table columns. One Option is: TRUNCATE ...
Read more >MySQL Reset Auto-Increment - Javatpoint
Similar to the TRUNCATE TABLE query, the pair of DROP TABLE and CREATE TABLE statements first drop the table and then recreate it....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
For other Postgres users looking for a solution to this, I’ve found that this works well:
thanks @ais-one, you lead me to good path. I would just want to add, your sintax is database specific, and to another guy reading this, @ais-one solution might not work for you, dependint what db you are using.
To reset id in Postgres you need to specify <YOUTtableNAME_id_seq> It looks like this, usually do it after I delete all the tables.