Skip to main content

What are Fields?

Fields are individual pieces of content within a collection, representing the columns in your database table. Each field has a specific data type and configuration that determines what kind of information it can store and how it’s displayed in the Directus app.
Every field in Directus has both a schema (the database column definition) and meta (the app interface configuration).

Field Structure

A field consists of three main components:

Field Schema

The schema defines the database column properties:
  • data_type - SQL data type
  • max_length - Maximum length for strings
  • is_nullable - Whether NULL values are allowed
  • is_primary_key - Primary key designation
  • has_auto_increment - Auto-increment for integers
  • is_unique - Unique constraint
  • is_indexed - Database index
  • default_value - Default value for new items
  • numeric_precision - Precision for decimal numbers
  • numeric_scale - Scale for decimal numbers

Field Meta

The meta defines how the field appears in the app:

Field Types

Directus supports a comprehensive set of field types that map to database column types:

Scalar Types

Geometry Types

Support for spatial data:
  • geometry
  • geometry.Point
  • geometry.LineString
  • geometry.Polygon
  • geometry.MultiPoint
  • geometry.MultiLineString
  • geometry.MultiPolygon

Alias Types

Alias fields don’t exist in the database but provide virtual functionality:
  • alias - No database column, UI only
  • o2m - One-to-Many relationship (virtual)
  • m2m - Many-to-Many relationship (virtual)
  • m2a - Many-to-Any relationship (virtual)
  • files - File relationships
  • translations - Translation interface
Alias fields are marked with alias: true in the schema and don’t create database columns. They’re used for relationships and computed values.

Creating Fields

Fields can be created through the API:
From the source code (~/workspace/source/api/src/services/fields.ts:359-431), creating a field:
  1. Validates the field doesn’t already exist
  2. Adds database-specific flags for type handling
  3. Creates or alters the database table
  4. Saves metadata to directus_fields
  5. Automatically assigns a sort order

Field Interfaces

Interfaces determine how fields are displayed and edited in the app:

Common Interfaces

  • input - Simple text input
  • textarea - Multi-line text
  • wysiwyg - Rich text editor
  • markdown - Markdown editor
  • dropdown - Select from predefined options
  • checkboxes - Multiple choice selection
  • toggle - Boolean switch
  • slider - Numeric slider
  • datetime - Date/time picker
  • file-image - Image upload
  • select-dropdown-m2o - Many-to-One relationship selector
  • list-o2m - One-to-Many relationship list

Interface Options

Each interface has specific options:

Field Displays

Displays control how field values appear in item listings:
  • formatted-value - Formatted number/date
  • boolean - Checkmark/X icon
  • color - Color swatch
  • datetime - Formatted date/time
  • image - Thumbnail image
  • labels - Colored labels
  • rating - Star rating
  • related-values - Display related item fields

Field Validation

Validation rules ensure data integrity using filter syntax:

System Fields

Directus automatically includes system fields in collections:
  • id - Primary key (auto-generated)
  • user_created - User who created the item
  • user_updated - User who last updated the item
  • date_created - Creation timestamp
  • date_updated - Last update timestamp
System fields cannot be deleted and have restricted modification. Only the is_indexed schema property can be changed.
From the source code (~/workspace/source/api/src/controllers/fields.ts:138-144):

Conditional Fields

Fields can be shown/hidden based on conditions:

Field Groups

Organize related fields into collapsible groups:
Then assign fields to the group:

Updating Fields

Update field schema or metadata:
Changing field types may result in data loss. Always backup your data before modifying field schemas.

Deleting Fields

Deleting a field removes both the database column and metadata:
From the source code (~/workspace/source/api/src/services/fields.ts:697-903), deleting a field:
  1. Removes related foreign key constraints and relationships
  2. Drops the database column
  3. Deletes metadata from directus_fields
  4. Updates permissions to remove field references
  5. Cleans up collection metadata references

Common Use Cases

Rich Content

Use WYSIWYG or Markdown fields for article bodies, product descriptions, and formatted text content.

Media Management

File and image fields with transformation options for galleries, featured images, and document attachments.

Relational Data

M2O, O2M, and M2M fields to create relationships between collections like authors, categories, and tags.

JSON Data

JSON fields for flexible, schema-less data like product options, metadata, or API responses.

Best Practices

Choose Appropriate Types: Use the most specific type for your data (e.g., integer over string for numbers).
Add Validation: Define validation rules to ensure data quality and prevent invalid entries.
Use Helpful Notes: Add descriptive notes to guide content editors on field usage.
Set Sensible Defaults: Provide default values for fields when appropriate to streamline content creation.
Index Wisely: Add indexes to fields used in filters and sorts, but avoid over-indexing as it impacts write performance.