Represents a single table in a database schema.
Can either be populated using the reflection API's or by incrementally building an instance using methods.
Once created TableSchema instances can be added to Schema\Collection objects. They can also be converted into SQL using the createSql(), dropSql() and truncateSql() methods.
string 'cascade'
Foreign key cascade action
string 'noAction'
Foreign key no action
string 'restrict'
Foreign key restrict action
string 'setDefault'
Foreign key restrict default
string 'setNull'
Foreign key set null action
string 'foreign'
Foreign constraint type
string 'primary'
Primary constraint type
string 'unique'
Unique constraint type
string 'fulltext'
Fulltext index type
string 'index'
Index - index type
int 4294967295
Column length when using a long column type
int 16777215
Column length when using a medium column type
int 255
Column length when using a tiny column type
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
array<string, array<string, mixed>>Additional type specific properties.
array<string, mixed>The valid keys that can be used in a column definition.
array<string, array>Columns in the table.
array<string, array<string, mixed>>Constraints in the table.
array<string, mixed>The valid keys that can be used in an index definition.
array<string, array>Indexes in the table.
array<string, mixed>Options for the table.
stringThe name of the table
boolWhether the table is temporary
array<string, string>A map with columns to types
array<string>Names of the valid constraint types.
array<string>Names of the valid foreign key actions.
array<string>Names of the valid index types.
array<string, int>Valid column length that can be used with text type columns
Constructor.
Returns an array of the table schema.
Helper method to check/validate foreign keys.
Add a column to the table.
Add a constraint.
Generate the SQL statements to add the constraints to the table
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.
Generate the SQL to create the Table.
Get a hash of columns and their default values.
Remove a constraint.
Generate the SQL statements to drop the constraints to the table
Generate the SQL to drop a table.
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.
Get the column(s) used for the primary key.
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.
Generate the SQL statements to truncate a table
Returns an array where the keys are the column names in the schema and the values the database type they have.
__construct(string $table, array<string, array|string> $columns = [])
Constructor.
string $table The table name.
array<string, array|string> $columns optional The list of columns for the schema.
__debugInfo(): array<string, mixed>
Returns an array of the table schema.
array<string, mixed>_checkForeignKey(array<string, mixed> $attrs): array<string, mixed>
Helper method to check/validate foreign keys.
array<string, mixed> $attrs Attributes to set.
array<string, mixed>Cake\Database\Exception\DatabaseExceptionaddColumn(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 array<string, mixed>|string $attrs $thisaddConstraint(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 array<string, mixed>|string $attrs $thisaddConstraintSql(Cake\Database\Connection $connection): array
Generate the SQL statements to add the constraints to the table
Cake\Database\Connection $connection arrayaddIndex(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 array<string, mixed>|string $attrs $thisbaseColumnType(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 string|nullcolumns(): 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>createSql(Cake\Database\Connection $connection): array
Generate the SQL to create the Table.
Uses the connection to access the schema dialect to generate platform specific SQL.
Cake\Database\Connection $connection arraydefaultValues(): array<string, mixed>
Get a hash of columns and their default values.
array<string, mixed>dropConstraint(string $name): $this
Remove a constraint.
string $name $thisdropConstraintSql(Cake\Database\Connection $connection): array
Generate the SQL statements to drop the constraints to the table
Cake\Database\Connection $connection arraydropSql(Cake\Database\Connection $connection): array
Generate the SQL to drop a table.
Uses the connection to access the schema dialect to generate platform specific SQL.
Cake\Database\Connection $connection arraygetColumn(string $name): array<string, mixed>|null
Get column data in the table.
string $name array<string, mixed>|nullgetColumnType(string $name): string|null
Returns column type or null if a column does not exist.
string $name string|nullgetConstraint(string $name): array<string, mixed>|null
Read information about a constraint based on name.
string $name array<string, mixed>|nullgetIndex(string $name): array<string, mixed>|null
Read information about an index based on name.
string $name array<string, mixed>|nullgetOptions(): 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.
boolhasColumn(string $name): bool
Returns true if a column exists in the schema.
string $name boolindexes(): 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 boolisTemporary(): bool
Gets whether the table is temporary in the database.
boolname(): string
Get the name of the table.
stringprimaryKey(): array
Get the column(s) used for the primary key.
arrayremoveColumn(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 $thissetColumnType(string $name, string $type): $this
Sets the type of a column.
string $name string $type $thissetOptions(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 $thissetTemporary(bool $temporary): $this
Sets whether the table is temporary in the database.
bool $temporary $thistruncateSql(Cake\Database\Connection $connection): array
Generate the SQL statements to truncate a table
Cake\Database\Connection $connection arraytypeMap(): 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>Additional type specific properties.
array<string, array<string, mixed>>The valid keys that can be used in a column definition.
array<string, mixed>Columns in the table.
array<string, array>Constraints in the table.
array<string, array<string, mixed>>The valid keys that can be used in an index definition.
array<string, mixed>Indexes in the table.
array<string, array>Options for the table.
array<string, mixed>The name of the table
stringWhether the table is temporary
boolA map with columns to types
array<string, string>Names of the valid constraint types.
array<string>Names of the valid foreign key actions.
array<string>Names of the valid index types.
array<string>Valid column length that can be used with text type columns
array<string, int>
© 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/class-Cake.Database.Schema.TableSchema.html