Migrate fails on new project?

Hi guys,

I am trying to set up a new project with Yii2. I have one running and want to make a new one, but seem to get stuck during setup process. I can work around it, however just curious what is causing this problem:




Yii Migration Tool (based on Yii v2.0.3)


Exception 'yii\db\Exception' with message 'SQLSTATE[HY000] [2002] No such file or directory'


in /Applications/MAMP/htdocs/yii-application/vendor/yiisoft/yii2/db/Connection.php:534


Stack trace:

#0 /Applications/MAMP/htdocs/yii-application/vendor/yiisoft/yii2/db/Connection.php(836): yii\db\Connection->open()

#1 /Applications/MAMP/htdocs/yii-application/vendor/yiisoft/yii2/db/Connection.php(823): yii\db\Connection->getMasterPdo()

#2 /Applications/MAMP/htdocs/yii-application/vendor/yiisoft/yii2/db/Command.php(208): yii\db\Connection->getSlavePdo()

#3 /Applications/MAMP/htdocs/yii-application/vendor/yiisoft/yii2/db/Command.php(816): yii\db\Command->prepare(true)

#4 /Applications/MAMP/htdocs/yii-application/vendor/yiisoft/yii2/db/Command.php(350): yii\db\Command->queryInternal('fetchAll', NULL)

#5 /Applications/MAMP/htdocs/yii-application/vendor/yiisoft/yii2/db/mysql/Schema.php(198): yii\db\Command->queryAll()

#6 /Applications/MAMP/htdocs/yii-application/vendor/yiisoft/yii2/db/mysql/Schema.php(97): yii\db\mysql\Schema->findColumns(Object(yii\db\TableSchema))

#7 /Applications/MAMP/htdocs/yii-application/vendor/yiisoft/yii2/db/Schema.php(140): yii\db\mysql\Schema->loadTableSchema('migration')

#8 /Applications/MAMP/htdocs/yii-application/vendor/yiisoft/yii2/console/controllers/MigrateController.php(121): yii\db\Schema->getTableSchema('{{%migration}}', true)

#9 /Applications/MAMP/htdocs/yii-application/vendor/yiisoft/yii2/console/controllers/BaseMigrateController.php(610): yii\console\controllers\MigrateController->getMigrationHistory(NULL)

#10 /Applications/MAMP/htdocs/yii-application/vendor/yiisoft/yii2/console/controllers/BaseMigrateController.php(102): yii\console\controllers\BaseMigrateController->getNewMigrations()

#11 [internal function]: yii\console\controllers\BaseMigrateController->actionUp(0)

#12 /Applications/MAMP/htdocs/yii-application/vendor/yiisoft/yii2/base/InlineAction.php(55): call_user_func_array(Array, Array)

#13 /Applications/MAMP/htdocs/yii-application/vendor/yiisoft/yii2/base/Controller.php(151): yii\base\InlineAction->runWithParams(Array)

#14 /Applications/MAMP/htdocs/yii-application/vendor/yiisoft/yii2/console/Controller.php(91): yii\base\Controller->runAction('', Array)

#15 /Applications/MAMP/htdocs/yii-application/vendor/yiisoft/yii2/base/Module.php(455): yii\console\Controller->runAction('', Array)

#16 /Applications/MAMP/htdocs/yii-application/vendor/yiisoft/yii2/console/Application.php(161): yii\base\Module->runAction('migrate', Array)

#17 /Applications/MAMP/htdocs/yii-application/vendor/yiisoft/yii2/console/Application.php(137): yii\console\Application->runAction('migrate', Array)

#18 /Applications/MAMP/htdocs/yii-application/vendor/yiisoft/yii2/base/Application.php(375): yii\console\Application->handleRequest(Object(yii\console\Request))

#19 /Applications/MAMP/htdocs/yii-application/yii(31): yii\base\Application->run()

#20 {main}




I loaded Yii2 with composer. Run init and set it to dev. Updated database settings in common/config/main-local.php and then tried to run the migrate so it makes the user and migrate table. However, it fails at that last point.

Is this a bug? Or am I doing something wrong?

I never had problems with migrations so far so I don’t think it is a bug. ;)

What command exactly have you executed?

Have you created other migrations?

Or was it sipmly the user table?

Also when you google for the error:

"SQLSTATE[HY000] [2002] No such file or directory"

You fill find answer related to DB settings.

  1. Use IP instead of hostname as DB host.

  2. Ensure that you have setup the mySQL provider correnctly. (has your DSN mysql config? Or is im maybe pointing to mssql config or something else?

Regards

Hi Lifelogger,

I have encountered the very same error when I forgot to start the MySQL server on my dev machine. You can also try double check the host and port (defaults to[font=monospace][color=#000000] 127.0.0.1:3306)[/color][/font]of the DB server and try to use ‘127.0.0.1’ instead of ‘localhost’ in the config file.

The command I run is: ./yii migrate

I run it on my local machine, where I already have a Yii2 project running on. That project workes fine. Never had a problem. Even with the same settings as the other project it will not work. Pretty strange.

Hmmm, problem seems to be my MAMP Pro installation. Migrate no longer works on my other Yii2 project too.

Thanks for the help guys. Have to look at my installation.