重置H2中的自动增量 [英] Resetting autoincrement in h2

查看:91
本文介绍了重置H2中的自动增量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在测试一个返回json响应的控制器,但是测试 第一次后失败,因为h2数据库未重置 自动递增编号. 使用夹具或手动创建对象也存在相同的问题.

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 or creating objects manually has a same problem.

@Before
public void setUp() {
    Fixtures.deleteAllModels();
    Fixtures.loadModels("data.yaml");
}

如何解决这个问题?

推荐答案

启动您的Play应用,使用以下网址启动浏览器(如果您在本地运行Play应用):

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

http://localhost:9000/@db

输入您的h2数据库,然后键入以下命令并运行:

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

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

如果您希望通过编程方式执行此操作,则Fixtures.executeSQL()可能会有用

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

有关更多信息,请检查 http://www.h2database.com/html/grammar.html#alter_table_alter

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

这篇关于重置H2中的自动增量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆