Fix errors from too many fields in a form ​

After you add many custom fields to a form, ERPNext can fail to save the field or the document. This page explains why, and how to fix it.

The errors ​

  • "Row size too large": ERPNext cannot add the new field, because the database row is full.
  • "Unknown column ... in INSERT INTO": a document fails to save after you add a custom field. ERPNext could not create the database column for the field.

Why it happens ​

Each DocType is a table in the database, and each field is a column. MariaDB and MySQL limit the size of one row to 65,535 bytes.

  • Data, Link, Select, Dynamic Link, Password, and Read Only fields use up to 140 characters by default. Each character takes up to 3 bytes, so each field reserves up to 420 bytes.
  • 65,535 ÷ 420 gives about 156 such fields in one table.

Large forms, such as Stock Entry or Sales Invoice, already have many fields. Apps can add more. The next custom field can then pass the limit.

Fix it without changing the database ​

Move the fields to a separate DocType ​

Use this when you need a group of related fields, for example the fields for one department or one process.

  1. Create a new DocType with the fields. Read Create a DocType.
  2. In the new DocType, add a Link field to the main DocType, for example to Stock Entry.
  3. Optional: add a Link field to the new DocType on the main form, for easy navigation.

The new DocType has its own table, with its own row size limit.

Move the fields to a child table ​

Use this when the fields repeat in rows, for example a quality checklist.

  1. Create a new DocType, and select Is Child Table.
  2. Add the fields to it.
  3. In Customize Form for the main DocType, add a Table field. Set Options to the new child DocType.

A child table also has its own database table.

Make the fields smaller ​

Change the field type to a text type ​

Small Text, Text, Text Editor, and Code fields store their content outside the row. They use only 9 to 12 bytes of the row.

In Customize Form, change custom Data, Link, or Select fields that hold long values, and that you do not filter or sort on, to Small Text or Text.

Reduce the length of fields ​

The Length property sets how many characters a field reserves. The default is 140. For a code that never has more than 20 characters, set Length to 20. The field then reserves 60 bytes instead of 420.

Remove the columns of deleted fields ​

When you delete a custom field, its database column stays and still uses space. To remove these columns, select Trim Table in the Actions menu of Customize Form. On a self-hosted site, you can also run the bench trim-tables command.

WARNING

Trimming deletes the data in those columns, and you cannot undo it. Take a backup of the database first.

Choose a fix ​

Your situationFix
You need many new fields with one value eachMove them to a separate DocType
You need rows of data in each documentMove them to a child table
A few fields push the form over the limitChange them to Small Text or Text, or reduce their length
You deleted custom fields, but their columns remainTrim the table