Resetting autoincrement in h2

前端 未结 3 730
无人及你
无人及你 2021-01-04 20:38

I\'m testing a controller that returns a json response but the tests fail after the first time because the h2 database does not reset the auto increment id. Using fixtures o

3条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-04 21:03

    Execute an SQL-script on your table:

    TRUNCATE TABLE my_table RESTART IDENTITY;
    ALTER SEQUENCE my_table_id_seq RESTART WITH 1;
    

    H2 should be of version 1.4.200 or higher.

    See https://www.h2database.com/html/commands.html

提交回复
热议问题