Dulf
Dulf

Reputation: 13

Yii2 and postgres connecttion

I tried yii2 and postgres database but when I try to query my table i got an error . How to fix this?

LINK for my error: Screenshot


LINK for my database connection:

Screenshot

Upvotes: 1

Views: 1483

Answers (1)

sxn
sxn

Reputation: 167

maybe you don't set defaultSchema on connection string

    return [
    'class' => 'yii\db\Connection',
    'dsn' => 'pgsql:host=localhost;dbname=db_name', 
    'username' => 'db_username',
    'password' => 'db_password',
    'charset' => 'utf8',
    'schemaMap' => [
      'pgsql'=> [
        'class'=>'yii\db\pgsql\Schema',
        'defaultSchema' => 'public' //specify your schema here
      ]
    ], // PostgreSQL
];

see to here

OR change your tableName() function in model like this

/**
 * @inheritdoc
 */
public static function tableName()
{
    return 'schemaName.table_name';
}

Upvotes: 4

Related Questions