Skip to content
On this page

Directus Cloud

Everything you need to start building. Provisioned in 90 seconds. Starting at $15/month.

Get Started

This is an auto-generated document to support extension builders understand the internal packages they can utilize. To find our written guides, tutorials, and API/SDK reference, check out our main docs .

Directus / @directus/sdk / rest / createField

Function: createField() ​

createField<Schema, TQuery>(collection, item, query?): RestCommand<IfAny<Schema, Record<string, any>, { [K in string | number | symbol]: Merge<MappedFunctionFields<Schema, DirectusField<Schema>> extends FF ? MapFlatFields<DirectusField<Schema>, FieldsWildcard<DirectusField<Schema>, Exclude<UnpackList<Mutable<(...)>>, PickRelationalFields<(...)> extends never ? never : AllKeys<(...)>>>, FF extends Record<string, string> ? FF<FF> : Record<string, string>> : never, PickRelationalFields<UnpackList<Mutable<TQuery["fields"]>>> extends never ? never : { [Field in string | number | symbol]: Field extends keyof DirectusField<Schema> ? Extract<(...)[(...)], ItemType<(...)>> extends RelatedCollection ? IsNullable<(...)[(...)], (...) | (...), (...) extends (...) ? (...) : (...)> : never : never }>[K] }>, Schema>

Defined in: rest/commands/create/fields.ts:21

Create a new field in the given collection.

Type Parameters ​

• Schema

• TQuery extends Query<Schema, DirectusField<Schema>>

Parameters ​

collection ​

keyof Schema

The collection to create a field for

item ​

The field to create

collection? ​

string

field? ​

string

meta? ​

NestedUnion<IfAny<Schema, { collection: string; conditions: null | FieldMetaConditionType[]; display: null | string; display_options: null | Record<string, any>; field: string; group: null | string; hidden: boolean; id: number; interface: null | string; note: null | string; options: null | Record<string, any>; readonly: boolean; required: boolean; sort: null | number; special: null | string[]; translations: null | FieldMetaTranslationType[]; validation: null | Record<string, any>; validation_message: null | string; width: null | string; }, "directus_fields" extends keyof Schema ? UnpackList<Schema[keyof Schema & "directus_fields"]> extends Item ? { [Field in string | number | symbol]: Item[Field] } & object : never : object>>

schema? ​

{ comment: null | string; data_type: string; default_value: any; foreign_key_column: null | string; foreign_key_schema: null | string; foreign_key_table: null | string; generation_expression: unknown; has_auto_increment: boolean; is_generated: boolean; is_indexed: boolean; is_nullable: boolean; is_primary_key: boolean; is_unique: boolean; max_length: null | number; name: string; numeric_precision: null | number; numeric_scale: null | number; schema: string; table: string; }

schema.comment? ​

null | string

schema.data_type? ​

string

schema.default_value? ​

any

schema.foreign_key_column? ​

null | string

schema.foreign_key_schema? ​

null | string

schema.foreign_key_table? ​

null | string

schema.generation_expression? ​

unknown

schema.has_auto_increment? ​

boolean

schema.is_generated? ​

boolean

schema.is_indexed? ​

boolean

schema.is_nullable? ​

boolean

schema.is_primary_key? ​

boolean

schema.is_unique? ​

boolean

schema.max_length? ​

null | number

schema.name? ​

string

schema.numeric_precision? ​

null | number

schema.numeric_scale? ​

null | number

schema.schema? ​

string

schema.table? ​

string

type? ​

string

query? ​

TQuery

Optional return data query

Returns ​

RestCommand<IfAny<Schema, Record<string, any>, { [K in string | number | symbol]: Merge<MappedFunctionFields<Schema, DirectusField<Schema>> extends FF ? MapFlatFields<DirectusField<Schema>, FieldsWildcard<DirectusField<Schema>, Exclude<UnpackList<Mutable<(...)>>, PickRelationalFields<(...)> extends never ? never : AllKeys<(...)>>>, FF extends Record<string, string> ? FF<FF> : Record<string, string>> : never, PickRelationalFields<UnpackList<Mutable<TQuery["fields"]>>> extends never ? never : { [Field in string | number | symbol]: Field extends keyof DirectusField<Schema> ? Extract<(...)[(...)], ItemType<(...)>> extends RelatedCollection ? IsNullable<(...)[(...)], (...) | (...), (...) extends (...) ? (...) : (...)> : never : never }>[K] }>, Schema>

The field object for the created field.