An interface used by database TableSchema objects.
string
'biginteger'
Big Integer column type
string
'binary'
Binary column type
string
'binaryuuid'
Binary UUID column type
string
'boolean'
Boolean column type
string
'char'
Char column type
string
'date'
Date column type
string
'datetime'
Datetime column type
string
'datetimefractional'
Datetime with fractional seconds column type
string
'decimal'
Decimal column type
string
'float'
Float column type
string
'integer'
Integer column type
string
'json'
JSON column type
string
'smallinteger'
Small Integer column type
string
'string'
String column type
string
'text'
Text column type
string
'time'
Time column type
string
'timestamp'
Timestamp column type
string
'timestampfractional'
Timestamp with fractional seconds column type
string
'timestamptimezone'
Timestamp with time zone column type
string
'tinyinteger'
Tiny Integer column type
string
'uuid'
UUID column type
Add a column to the table.
Add a constraint.
Add an index.
Returns the base type name for the provided column. This represent the database type a more complex class is based upon.
Get the column names in the table.
Get the names of all the constraints in the table.
Get a hash of columns and their default values.
Remove a constraint.
Get column data in the table.
Returns column type or null if a column does not exist.
Read information about a constraint based on name.
Read information about an index based on name.
Gets the options for a table.
Get the column(s) used for the primary key.
Check whether a table has an autoIncrement column defined.
Returns true if a column exists in the schema.
Get the names of all the indexes in the table.
Check whether a field is nullable
Gets whether the table is temporary in the database.
Get the name of the table.
Remove a column from the table schema.
Sets the type of a column.
Sets the options for a table.
Sets whether the table is temporary in the database.
Returns an array where the keys are the column names in the schema and the values the database type they have.
addColumn(string $name, array<string, mixed>|string $attrs): $this
Add a column to the table.
Columns can have several attributes:
type
The type of the column. This should be one of CakePHP's abstract types.length
The length of the column.precision
The number of decimal places to store for float and decimal types.default
The default value of the column.null
Whether the column can hold nulls.fixed
Whether the column is a fixed length column. This is only present/valid with string columns.unsigned
Whether the column is an unsigned column. This is only present/valid for integer, decimal, float columns.In addition to the above keys, the following keys are implemented in some database dialects, but not all:
comment
The comment for the column.string
$name The name of the column
array<string, mixed>|string
$attrs The attributes for the column or the type name.
$this
addConstraint(string $name, array<string, mixed>|string $attrs): $this
Add a constraint.
Used to add constraints to a table. For example primary keys, unique keys and foreign keys.
type
The type of constraint being added.columns
The columns in the index.references
The table, column a foreign key references.update
The behavior on update. Options are 'restrict', 'setNull', 'cascade', 'noAction'.delete
The behavior on delete. Options are 'restrict', 'setNull', 'cascade', 'noAction'.The default for 'update' & 'delete' is 'cascade'.
string
$name The name of the constraint.
array<string, mixed>|string
$attrs The attributes for the constraint. If string it will be used as type
.
$this
Cake\Database\Exception\DatabaseException
addIndex(string $name, array<string, mixed>|string $attrs): $this
Add an index.
Used to add indexes, and full text indexes in platforms that support them.
type
The type of index being added.columns
The columns in the index.string
$name The name of the index.
array<string, mixed>|string
$attrs The attributes for the index. If string it will be used as type
.
$this
Cake\Database\Exception\DatabaseException
baseColumnType(string $column): string|null
Returns the base type name for the provided column. This represent the database type a more complex class is based upon.
string
$column The column name to get the base type from
string|null
columns(): array<string>
Get the column names in the table.
array<string>
constraints(): array<string>
Get the names of all the constraints in the table.
array<string>
defaultValues(): array<string, mixed>
Get a hash of columns and their default values.
array<string, mixed>
dropConstraint(string $name): $this
Remove a constraint.
string
$name Name of the constraint to remove
$this
getColumn(string $name): array<string, mixed>|null
Get column data in the table.
string
$name The column name.
array<string, mixed>|null
getColumnType(string $name): string|null
Returns column type or null if a column does not exist.
string
$name The column to get the type of.
string|null
getConstraint(string $name): array<string, mixed>|null
Read information about a constraint based on name.
string
$name The name of the constraint.
array<string, mixed>|null
getIndex(string $name): array<string, mixed>|null
Read information about an index based on name.
string
$name The name of the index.
array<string, mixed>|null
getOptions(): array<string, mixed>
Gets the options for a table.
Table options allow you to set platform specific table level options. For example the engine type in MySQL.
array<string, mixed>
getPrimaryKey(): array<string>
Get the column(s) used for the primary key.
array<string>
hasAutoincrement(): bool
Check whether a table has an autoIncrement column defined.
bool
hasColumn(string $name): bool
Returns true if a column exists in the schema.
string
$name Column name.
bool
indexes(): array<string>
Get the names of all the indexes in the table.
array<string>
isNullable(string $name): bool
Check whether a field is nullable
Missing columns are nullable.
string
$name The column to get the type of.
bool
isTemporary(): bool
Gets whether the table is temporary in the database.
bool
name(): string
Get the name of the table.
string
removeColumn(string $name): $this
Remove a column from the table schema.
If the column is not defined in the table, no error will be raised.
string
$name The name of the column
$this
setColumnType(string $name, string $type): $this
Sets the type of a column.
string
$name The column to set the type of.
string
$type The type to set the column to.
$this
setOptions(array<string, mixed> $options): $this
Sets the options for a table.
Table options allow you to set platform specific table level options. For example the engine type in MySQL.
array<string, mixed>
$options The options to set, or null to read options.
$this
setTemporary(bool $temporary): $this
Sets whether the table is temporary in the database.
bool
$temporary Whether the table is to be temporary.
$this
typeMap(): array<string, string>
Returns an array where the keys are the column names in the schema and the values the database type they have.
array<string, string>
© 2005–present The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
https://api.cakephp.org/4.4/interface-Cake.Database.Schema.TableSchemaInterface.html