yii2 improved basic template

Hi All,

I am brand new to the Yii2 Framework and have spent some time reading through the 2.0 getting started documentation having fun with the basic template. All working great and have been able to manually create a PostgresDb as part of the exercises and also access this via the Gii tools.

I stumbled across the improved basic template over the weekend and wanted to try it out locally. However I’m having real trouble trying to run the ‘./yii migrate’ command from the console and keep getting the following error:

Exception 'yii\db\Exception' with message 'could not find driver'

in /Applications/MAMP/htdocs/advanced/_protected/vendor/yiisoft/yii2/db/Connection.php:534

Stack trace:

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

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

#2 /Applications/MAMP/htdocs/advanced/_protected/vendor/yiisoft/yii2/db/Schema.php(382): yii\db\Connection->getSlavePdo()

#3 /Applications/MAMP/htdocs/advanced/_protected/vendor/yiisoft/yii2/db/Connection.php(732): yii\db\Schema->quoteValue('migration')

#4 /Applications/MAMP/htdocs/advanced/_protected/vendor/yiisoft/yii2/db/pgsql/Schema.php(319): yii\db\Connection->quoteValue('migration')

#5 /Applications/MAMP/htdocs/advanced/_protected/vendor/yiisoft/yii2/db/pgsql/Schema.php(160): yii\db\pgsql\Schema->findColumns(Object(yii\db\TableSchema))

#6 /Applications/MAMP/htdocs/advanced/_protected/vendor/yiisoft/yii2/db/Schema.php(139): yii\db\pgsql\Schema->loadTableSchema('migration')

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

#8 /Applications/MAMP/htdocs/advanced/_protected/vendor/yiisoft/yii2/console/controllers/BaseMigrateController.php(604): yii\console\controllers\MigrateController->getMigrationHistory(NULL)

#9 /Applications/MAMP/htdocs/advanced/_protected/vendor/yiisoft/yii2/console/controllers/BaseMigrateController.php(99): yii\console\controllers\BaseMigrateController->getNewMigrations()

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

#11 /Applications/MAMP/htdocs/advanced/_protected/vendor/yiisoft/yii2/base/InlineAction.php(55): call_user_func_array(Array, Array)

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

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

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

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

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

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

#18 /Applications/MAMP/htdocs/advanced/_protected/yii(23): yii\base\Application->run()

#19 {main}

I have since installed MYSQL and the Sequel Pro tool on my mac. I have create a db called ‘robone’ and my ‘_protected/config/db.php’ looks as follows:


return [

    'class' => 'yii\db\Connection',

    'dsn' => 'pgsql:host=localhost;dbname=robone',

    'username' => 'root',

    'password' => 'XXXXXXX',

    'charset' => 'utf8',


I am running using MAMP which all seems to work fine for the original basic template. I’ve al so run phpinfo() to check that I have mysql pdo installed and all looks fine there.

Really getting stuck with this now and I’m sure it’s probably something really simple I’m missing is anyone able to offer some hugely appreciated sage advice?


If you are using mysql, your dsn should be:

'dsn' => 'mysql:host=localhost;dbname=robone',

Related to error with pgsql, try this:



and on line 19, change driver name from ‘postgresql’ to ‘pgsql’.

Also on line 32 change :

'data' => 'LONGBLOB NOT NULL',


'data' => ''.$dataType.' NOT NULL',

That is my mistake, didn’t saw that in basic template :D

I have never used this DBMS so maybe I made a mistake there. If these things caused problems, I will fix them soon in the next release of templates ( probably tomorrow ).

Thanks Nenad!

Such a silly error on my part, my own fault for jumping between postgres and mysql. I have amended my db.php file to ‘mysql’ as you suggested and this has resolved my issue running the migrate.

I continued with the installation instructions for the improved basic template and completed running the final step 7:

This seemed to complete correctly but when I now navigate to localhost:8888/advanced/web/index.php (my homepage) I’m I getting the following error:

SQLSTATE[28000] [1045] Access denied for user 'root'@'localhost' 

I am using root as username for mysql db and the supplied MYSQL_PASSWORD that was added as part of my mysql install. Is this correct or is it meant to be a login relating to the template rather than mysql install?

Thanks in advance.

Why localhost:8888/advanced/web/index.php ? Improved template do not work like that.





These are the same.

If you are using advanced template, and you want to see backend side, visit:


Rob212 and I have discussed his problem with connecting to database in private chat.

His error was :

SQLSTATE[42000] [1049] Unknown database 'robone'

Solution was to change:

'dsn' => 'mysql:host=localhost;dbname=robone',


'dsn' => 'mysql:host=;dbname=robone',

in his db configuration.

It seems that packages like MAMP for Mac, Xampp for Linux an maybe some other too, do not like when you use "host=localhost", you should change to "host=".