Console Commands
You can run any command from the application root with bin/cake [command].
Compact help command
The plugin provides an optional compact help command that replaces the core help with a more readable format, using bracket notation for subcommands.
Enable it in your configuration:
'Setup' => [
'compactHelp' => true,
],When enabled, bin/cake help displays commands in a compact format:
Available Commands:
- bake [controller|model|template|...]
- cache [clear|clear_all|list]
- migrations [migrate|rollback|status|...]Use bin/cake help -v for verbose output with descriptions and plugin grouping.
You can also filter by command prefix:
bin/cake help bakeApplication maintenance
CurrentConfig
These commands quickly show the current config, for both the database and the cache:
bin/cake current_config displayYou can also quickly view the phpinfo() output:
bin/cake current_config phpinfoFilter with grep
On Linux systems (or any container/VM environment), use grep to quickly filter the output. For example, to see only your Xdebug settings for CLI:
bin/cake current_config phpinfo | grep xdebugThis is very useful and quicker than any other lookup on the CLI.
Database
Init
Initialize the database:
bin/cake db initReset
Remove all content from the tables, excluding the phinx migration tables:
bin/cake db resetWARNING
Be careful — make sure you have a backup before doing this.
Wipe
Hard-reset the database, dropping all tables:
bin/cake db wipeWARNING
Be careful — make sure you have a backup before doing this.
Database integrity
Keys
Alerts you about possible non-unsigned integer (foreign) keys, in terms of data-integrity issues.
- Provides migration-file content to be executed.
- This is a prerequisite for constraints and other features that need the keys to be aligned.
Constraints
Alerts you about possible missing constraints, in terms of data-integrity issues.
- Provides migration-file content to be executed.
- Optionally relates a foreign key that is not set back to
NULLwhen the relatedhas*entity is removed. This is only relevant if the relation is notdependent => true.
Nulls
Checks for fields that might need to be nullable, or the opposite.
- Converts
NULLfields without a default value.
Bools
Checks all boolean field types — usually tinyint(1) — for a valid schema.
Since MySQL 8+ they can no longer be unsigned, or the length is lost (making them normal tinyint or enums). To avoid this, run this on a database older than v8 and then perform a safe migration toward 8+.
- Converts any bool field to a signed one.
Ints
Integers in newer MySQL versions lose their length as part of the schema definition. To preserve this sometimes-important metadata, it can be written (and later reused) into the column comment as metadata.
- Adds the length info to the comment as a prefix (
[schema] length: x).
Database data validation
These commands help detect and fix invalid data in the database.
Dates
Check for invalid zero date/datetime values (0000-00-00 or 0000-00-00 00:00:00):
bin/cake db_data datesOptions:
-f, --fix: Fix invalid dates by setting them toNULL.-c, --connection: Database connection to use (default:default).- Use
-vfor verbose output, including the SQL fix statements.
You can also check a specific table:
bin/cake db_data dates usersEnums
Check for invalid enum values against PHP BackedEnum definitions:
bin/cake db_data enumsThis command:
- Validates values against PHP
BackedEnumclass definitions. - Detects MySQL
ENUMcolumns and suggests migrating toVARCHARplus a PHPBackedEnum. - Shows mismatches between the PHP and MySQL enum definitions.
Options:
-f, --fix: Fix invalid enum values by setting them toNULL.-p, --plugin: Plugin to check.-c, --connection: Database connection to use (default:default).- Use
-vfor verbose output, including the SQL fix statements.
You can also check a specific model:
bin/cake db_data enums UsersOrphans
Check for orphaned foreign-key records (FK values pointing to non-existent parents):
bin/cake db_data orphansThis is useful when constraints were not enforced historically, or after data migrations.
Options:
-f, --fix: Fix orphaned records by setting the FK toNULL.-d, --delete: Delete orphaned records instead of nullifying (use with--fix).-p, --plugin: Plugin to check.-c, --connection: Database connection to use (default:default).- Use
-vfor verbose output, including the SQL statements.
You can also check a specific model:
bin/cake db_data orphans UsersBackup: create and restore
Create
Dump a full database schema, including content, into a file in your backup folder. It uses mysqldump and is therefore the most performant option here.
Restore
Restore a dumped file into the database, overwriting the previous values there.
Other tools
CliTest
Lets you test certain features — such as routing — and how (or whether) they work in CLI:
bin/cake cli_testDepending on your domain it outputs something like:
Router::url('/'):
/
Router::url(['controller' => 'test']):
/test
Router::url('/', true):
http://example.local/
Router::url(['controller' => 'test'], true):
http://example.local/testUser
Lets you quickly add a new user to your users table, including a properly hashed password, so you can log in:
bin/cake user create [user]To update an existing user:
bin/cake user update [user]If you need to provide custom defaults, use a callback. Set it in your app.php:
'UserCreate.callable' => function (User $user): User {
// ...
return $user;
},Reset
Lets you reset all emails or passwords. This is very useful when copying live data dumps into your local development environment. Afterward you can log in with a known password for any user — for example after resetting all passwords to a shared development value:
bin/cake reset emailor
bin/cake reset pwdTooling
Mailmap
Creates a .mailmap file from your current commit history. Requires Git as a tool:
bin/cake mailmap generateThis is used, for example, in CakePHP to combine multiple accounts of the same user for git shortlog. Check the results with git shortlog -sne — it might require some manual adjustments afterward.
See also
- Bake Templates — enhanced scaffolding via the Setup theme.
- Web Backend — the same integrity tooling from the web.