Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Grails 斯波克和格拉尔斯:为什么出错了?_Grails_Spock - Fatal编程技术网

Grails 斯波克和格拉尔斯:为什么出错了?

Grails 斯波克和格拉尔斯:为什么出错了?,grails,spock,Grails,Spock,这是我在Grails 2.5.1中的集成测试:在setup()中有: Role roleAdmin = new Role(RoleType.ROLE_ADMIN.name(), 1000).save(failOnError: true, flush: true) Role roleMerchant = new Role(RoleType.ROLE_MERCHANT.name(), 1).save(failOnError: true, flush: true) Role roleProvider

这是我在Grails 2.5.1中的集成测试:在setup()中有:

Role roleAdmin = new Role(RoleType.ROLE_ADMIN.name(), 1000).save(failOnError: true, flush: true)
Role roleMerchant = new Role(RoleType.ROLE_MERCHANT.name(), 1).save(failOnError: true, flush: true)
Role roleProvider = new Role(RoleType.ROLE_PROVIDER.name(), 2).save(failOnError: true, flush: true)
Role roleUser = new Role(RoleType.ROLE_USER.name(), 3).save(failOnError: true, flush: true)

RoleGroup roleGroupAdmin = new RoleGroup(RoleGroupType.ADMIN.name()).save(failOnError: true, flush: true)
RoleGroup roleGroupCustomer = new RoleGroup(RoleGroupType.CUSTOMERS.name()).save(failOnError: true, flush: true)
RoleGroup roleGroupUsers = new RoleGroup(RoleGroupType.USERS.name()).save(failOnError: true, flush: true)

RoleGroupRole.create(roleGroupAdmin, roleAdmin, true)
RoleGroupRole.create(roleGroupCustomer, roleMerchant, true)
RoleGroupRole.create(roleGroupCustomer, roleProvider, true)
RoleGroupRole.create(roleGroupUsers, roleUser, true)
运行时,我出现以下错误:

| Error 2015-12-21 11:14:04,994 [main] ERROR spi.SqlExceptionHelper  - Cannot add or update a child row: a foreign key constraint fails (`pi_test`.`role_group_role`, CONSTRAINT `FK_dxc3snhixkg9qn3c46p6hyjli` FOREIGN KEY (`role_id`) REFERENCES `role` (`id`))
User
Role
RoleGroupRole
是s2 quickstart从
Spring Security Plugin
生成的标准类

为什么会发生这种情况?我刷新每个插入,但似乎找不到角色id和
RoleGroupRole

谢谢大家


Luis

提供的错误是不够的,请注意,除非在每次测试时清除数据库,否则必须先尝试读取\加载每个对象,然后再将其保存到数据库中。对!事实上,my Datasource.groovy有dbCreate=“create drop”,以避免读取脏数据。(测试数据库)提供的错误不充分,请注意,除非每次测试时清除数据库,否则必须先尝试读取\加载每个对象,然后再将其保存到数据库。对!事实上,my Datasource.groovy有dbCreate=“create drop”,以避免读取脏数据。(测试数据库)