Can't add instance of custom field type to entity I have a custom field type that I'm trying to add to a custom fieldable entity. The entity works fine and I've added other fields to it, my problem is when I go to add an instance of my field to the entity, I get the following SQL error:


  There was a problem creating field Authors: Exception thrown while 
  performing a schema update.
  SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'NOT NULL, PRIMARY KEY (entity_id, deleted, delta, langcode), INDEX bundle' at line 9: CREATE TABLE {myentity__field_myfield} ( bundle VARCHAR(128) CHARACTER SET ascii COLLATE ascii_general_ci NOT NULL DEFAULT '' COMMENT 'The field instance bundle to which this row belongs, used when deleting a field instance', deleted TINYINT NOT NULL DEFAULT 0 COMMENT 'A boolean indicating whether this data item has been deleted', entity_id INT unsigned NOT NULL COMMENT 'The entity id this data is attached to', revision_id INT unsigned NOT NULL COMMENT 'The entity revision id this data is attached to', langcode VARCHAR(32) CHARACTER SET ascii COLLATE ascii_general_ci NOT NULL DEFAULT '' COMMENT 'The language code for this data item.', delta INT unsigned NOT NULL COMMENT 'The sequence number for this data item, used for multi-value fields', field_myfield_target_uid INT unsigned NOT NULL COMMENT 'The user ID of the author', field_myfield_affiliation NOT NULL, PRIMARY KEY (entity_id, deleted, delta, langcode), INDEX bundle (bundle), INDEX revision_id (revision_id)  ) ENGINE = InnoDB DEFAULT CHARACTER SET utf8mb4 COMMENT 'Data storage for myentity field field_myfield.'; Array ( )


I've replaced my entity with myentity and my custom field type with myfield for the above. My schema definition for my field type is as follows:

/**
 * {@inheritdoc}
 */
public static function schema(FieldStorageDefinitionInterface 
$field_definition) {

  $columns = [
    // List the values that the field will save. This
    // field will only save a single value, 'value'
    'target_uid' =&gt; [
      'type' =&gt; 'int',
      'not null' =&gt; true,
      'unsigned' =&gt; true,
      'description' =&gt; "The user ID of the author"
    ],
    'affiliation' =&gt; [
      'type' =&gt; 'varchar',
      'size' =&gt; 255,
      'not null' =&gt; true
    ]
  ];

  $schema = [
    'columns' =&gt; $columns,
    // 'indexes' =&gt; [
    //   'target_uid'
    // ],
    // 'foreign keys' =&gt; [
    //   'target_uid'
    // ],
  ];

  return $schema;
}


I've looked at other core field types for guidance but I can't see where I'm going wrong.
You’re confusing the required length property of a varchar field with the size property of a text field.

Replace size with length (or varchar with text if that makes more sense) and your code should start working.