My Grails application and bootstrap work fine when dbCreate="create"
, but when I change it to dbCreate="update"
, I get object create validation errors in bootstrap. I'd just like my data to persist when I restart the application. From the error message, it appears I'm violating a unique constraints. Maybe the database isn't getting purged on restart? I've tried "create-drop"
Here is the code and error message below. Any insight is appreciated.
development {
dataSource {
dbCreate = "create-drop" // one of 'create', 'create-drop', 'update', 'validate', ''
url = "jdbc:h2:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000;"
}
}
class BootStrap {
def init = { servletContext ->
def adminRole = new com.testapp.Role(authority: 'ROLE_ADMIN').save(failOnError: true)
def userRole = new com.testapp.Role(authority: 'ROLE_USER').save(failOnError: true)
}
Message:
Validation Error(s) occurred during save(): - Field error in object 'com.testapp.Role' on field 'authority': rejected value [ROLE_ADMIN]; codes [com.testapp.Role.authority.unique.error.
default message [Property [{0}] of class [{1}] with value [{2}] must be unique