Search code examples
grailsgsp

Data truncation: Data too long for column grails GSP field


I have this domain class in my project. This is a sample

public class empHistory {

String respField
String addInfo

static constraints = {

        respField(nullable: true, maxSize:100)
        updatedByUser(nullable: true, maxSize:100)
    }

after providing the field value for both fields when i click ok its displaying the following error

Data truncation: Data too long for column 'respField' in row 1

Solution

  • I think you may have entered more than the specified max value. so if you need to expand the size for example you can do like this

    public class empHistory {
    
    String respField
    String addInfo
    
    static constraints = {
    
            respField(nullable: true, maxSize:2000)
            updatedByUser(nullable: true, maxSize:2000)
        }
    

    If dbcreate status is update change it to create or create-drop then try to run your application again. it's because the database is already created in the first constraint.