Error: 'Row size too large'
Got feedback or spotted a mistake?

Leave a comment at the end of this page or email contact@krishagni.com

Error: 'Row size too large'

Issue

When saving a form or adding new fields, a user encounters the error below:

Form Error: Error saving container: StatementCallback; bad SQL grammar [ALTER TABLE DE_E_xxxxx ADD (DE_A_102 VARCHAR(255))]; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Row size too large. The maximum row size for the used table type, not counting BLOBs, is 65535.

Cause

  1. This error occurs because MySQL limits the maximum row size to 65,535 bytes for the tables.

  2. Each new field you add (e.g., VARCHAR(255)) increases the row size.

  3. If too many fields are added, the combined size exceeds MySQL’s limit and refuses to add more fields.

Note: This error can come when syncing forms from other applications like REDCap or OpenClinica.

This is because the underlying MySQL database has a limitation (click here) on how many columns a table can support.

Workarounds

This problem has no fix since the underlying database imposes the limitation. Hence you are use the workarounds suggested:

  1. If the form is being created in OpenSpecimen: create multiple forms

  2. If the form is being synced from OC/RC: Ignore unwanted fields

  3. Use a Sub-Form - Break the form into smaller, related sub-forms. Each sub-form creates a separate table, avoiding the row size limit.
    Example: Instead of one 100-field form, create:

    1. Main Form: 50 fields

    2. Sub-form 1: 25 fields

    3. Sub-form 2: 25 fields

  4. Reduce Field Count (If data doesn’t exists)

    • Review existing fields and remove unnecessary ones.

    • Combine related fields into a single field when possible.

Best Practice

We recommend keeping form fields under ~70 to avoid reaching MySQL’s limit. If you expect more fields, design the form with sub-forms from the start.

Got feedback or spotted a mistake?

Leave a comment at the end of this page or email contact@krishagni.com