Resetting autoincrement in h2

梦想的初衷 提交于 2019-12-01 04:44:58

Start your play app, fire up browser with this url (if you run play app locally):

http://localhost:9000/@db

Enter your h2 db, and type the command below and run:

ALTER TABLE <table_name> ALTER COLUMN <column_name> RESTART WITH 1

If you'd like to do this programmatically, Fixtures.executeSQL() might be useful

For more information, check http://www.h2database.com/html/grammar.html#alter_table_alter

If you are using Spring, I found this blog post which suggests using @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)

So that each test uses a new application context, thereby resetting the db increments.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!