Cakephp 5.1.2 migrations error

just now i installed new cakephp 5.1.2 create migrations. I setup all mysql database event in cakephp 5x, but when i hit the migration command it throw error… please help whats wrong with here. if you guys release new cakephp version than first update the DOCUMENTS first than relase new the version.

Here is cli command:-

composer.json file:-

as the error states you are not able to connect to your mysql server.


This has nothing to do with updating docs or releasing new versions because nothing here has changed. Check your config/app_local.php Datasources section AND make sure when you open the CakePHP app for the first time (via e.g. bin/cake server) in your browser, that this is green.

thank you @KevinPfeifer to reply me. yes database indicator green there

app_local.php:-

but despite it i got again that error

do you actually have a migration present?

What does bin/cake migrations status present to you

yes! already checked it but same result, error throw
see here—

migration command status

Migration Directory there and Seeds too

Here is Migration files, copy from existing project
but Existing project same version cakephp 5.1.2

I have a suspicion: do you by chance have an environment variable set named DATABASE_URL

Try echo $DATABASE_URL in your terminal

This makes absolutes no sense to me.

The connection works if you do a web request but doesn’t in your CLI.

Do you have a different PHP environment set for your CLI compared to your webserver?

Everything is fine @KevinPfeifer, only migration command not working

Ok so now i open it cakephp built in server, http://localhost:8765 now it show red indicator, no database connection… event it is a error!
so what is the problem? if open it direct in url without port than it show database connection successfully with green button. So Is It a Bug?

If you don’t get the same page with the CakePHP built in server (which is just a plain old php -S localhost:8765) and your Apache Webserver it indicates to me, that you didn’t set the docroot properly in your apache webserver.

By “properly” I mean to a different CakePHP app, which works.

also be aware, that 'host' => 'localhost', means, that PHP tries to connect via a UNIX Socket.
Which UNIX is used can be found inside your PHP settings (or via a PHPInfo page)

If your MySQL server only allows IP connections then you probably need to adjust that to 'host' => '127.0.0.1',

1 Like

Yo!!! man thank @KevinPfeifer my problem solve. thank again its really hard work for me but you solve it man,