使用Yii2迁移创建表时出错

使用Yii2迁移创建表时出错,yii2,yii2-basic-app,Yii2,Yii2 Basic App,我对yii2相当陌生,我正在使用postgres,我的db.php文件是- return [ 'class' => 'yii\db\Connection', 'dsn' => 'pgsql:host=localhost;port=5432;dbname=xxxx', 'username' => 'postgres', 'password' => 'abc', 'charset' => 'utf8'

我对
yii2
相当陌生,我正在使用postgres,我的
db.php
文件是-

return [
       'class' => 'yii\db\Connection',
       'dsn' => 'pgsql:host=localhost;port=5432;dbname=xxxx',
       'username' => 'postgres',
       'password' => 'abc',
       'charset' => 'utf8',
];
我直接在postgres中创建了一个表,并使用
ActiveRecord
成功地获取了数据。 然后我开始使用迁移创建一个表

./yii migrate/create logins
它成功地在迁移文件夹中创建了一个文件,然后我将以下内容放入
up
方法中-

public function up()
{
    $this->createTable('logins', [
            'id' => Schema::TYPE_PK,
            'name' => Schema::TYPE_STRING . ' NOT NULL',
            'password' => Schema::TYPE_STRING . ' NOT NULL'
    ]);
}
并启动了
/yii migrate
,以更新数据库,但出现以下错误-

Yii Migration Tool (based on Yii v2.0.10)
Exception 'yii\db\Exception' with message 'could not find driver'
in /opt/lampp/htdocs/project/server/api/project/vendor/yiisoft/yii2/db/Connection.php:549

有什么我遗漏的步骤吗?或者postgres连接有问题?

我假设这是基本模板

确保已配置
db
组件

config/console.php
文件中,检查是否有
db
键入
组件
部分,如:

// ...
'components' => [
    // ...
    'db' => require(__DIR__ . '/db.php'),
    // ...
],
如果一切正常,但仍然存在错误,则需要检查是否正确安装了
pgsql
驱动程序


有关详细信息,请参阅。

您的控制台应用程序中是否配置了
db
组件?不,我没有,您能告诉我如何配置吗谢谢您的回复,是的,已经有这样一个组件部分。因此,请检查是否安装了驱动程序,查看我的更新答案。