yiiyii-components

SQLSTATE[HY000] [1049] on YiiFramework


$ yii migrate

Yii Migration Tool (based on Yii v2.0.13-dev)

Exception 'yii\db\Exception' with message 'SQLSTATE[HY000] [1049] Unknown database 'yii''

in E:\laragon\www\website\vendor\yiisoft\yii2\db\Connection.php:586

Stack trace:

    #0 E:\laragon\www\website\vendor\yiisoft\yii2\db\Connection.php(932): yii\db\Connection->open()
    #1 E:\laragon\www\website\vendor\yiisoft\yii2\db\Connection.php(919): yii\db\Connection->getMasterPdo()
    #2 E:\laragon\www\website\vendor\yiisoft\yii2\db\Command.php(219): yii\db\Connection->getSlavePdo()
    #3 E:\laragon\www\website\vendor\yiisoft\yii2\db\Command.php(1031): yii\db\Command->prepare(true)
    #4 E:\laragon\www\website\vendor\yiisoft\yii2\db\Command.php(362): yii\db\Command->queryInternal('fetchAll', NULL)
    #5 E:\laragon\www\website\vendor\yiisoft\yii2\db\mysql\Schema.php(320): yii\db\Command->queryAll()
    #6 E:\laragon\www\website\vendor\yiisoft\yii2\db\mysql\Schema.php(111): yii\db\mysql\Schema->findColumns(Object(yii\db\TableSchema))
    #7 E:\laragon\www\website\vendor\yiisoft\yii2\db\Schema.php(661): yii\db\mysql\Schema->loadTableSchema('migration')
    #8 E:\laragon\www\website\vendor\yiisoft\yii2\db\Schema.php(174): yii\db\Schema->getTableMetadata('{{%migration}}', 'schema', true)
    #9 E:\laragon\www\website\vendor\yiisoft\yii2\console\controllers\MigrateController.php(201): yii\db\Schema->getTableSchema('{{%migration}}', true)
    #10 E:\laragon\www\website\vendor\yiisoft\yii2\console\controllers\BaseMigrateController.php(864): yii\console\controllers\MigrateController->getMigrationHistory(NULL)
    #11 E:\laragon\www\website\vendor\yiisoft\yii2\console\controllers\BaseMigrateController.php(166): yii\console\controllers\BaseMigrateController->getNewMigrations()
    #12 [internal function]: yii\console\controllers\BaseMigrateController->actionUp(0)
    #13 E:\laragon\www\website\vendor\yiisoft\yii2\base\InlineAction.php(57): call_user_func_array(Array, Array)
    #14 E:\laragon\www\website\vendor\yiisoft\yii2\base\Controller.php(157): yii\base\InlineAction->runWithParams(Array)
    #15 E:\laragon\www\website\vendor\yiisoft\yii2\console\Controller.php(135): yii\base\Controller->runAction('', Array)
    #16 E:\laragon\www\website\vendor\yiisoft\yii2\base\Module.php(528): yii\console\Controller->runAction('', Array)
    #17 E:\laragon\www\website\vendor\yiisoft\yii2\console\Application.php(180): yii\base\Module->runAction('migrate', Array)
    #18 E:\laragon\www\website\vendor\yiisoft\yii2\console\Application.php(147): yii\console\Application->runAction('migrate', Array)
    #19 E:\laragon\www\website\vendor\yiisoft\yii2\base\Application.php(386): yii\console\Application->handleRequest(Object(yii\console\Request))
    #20 E:\laragon\www\website\yii(20): yii\base\Application->run()
    #21 {main}

this my db

return [ 'class' => 'yii\db\Connection', 'driverName' => 'mysql', 'dsn' => 'mysql:host=localhost;dbname=yii', 'username' => 'root', 'password' => '', 'charset' => 'utf8',

// Schema cache options (for production environment)
//'enableSchemaCache' => true,
//'schemaCacheDuration' => 60,
//'schemaCache' => 'cache', ];

Solution

  • The error message means you need to create a database name 'yii'.

    Just use Menu > MySQL > Create database to create the database.