1

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

Orlando Herrera
  • 3,481
  • 1
  • 34
  • 44
Dulf
  • 13
  • 7
  • You don't have **tbl_user** in database?!! – Insane Skull Feb 13 '17 at 05:55
  • Have you created model called `tbl_user`? Or is it your table name? If this is model than it's not there and that is why you've got error. If this should be table name go back to the [Guide](http://www.yiiframework.com/doc-2.0/guide-db-active-record.html) and read about ActiveRecord. – Bizley Feb 13 '17 at 06:44
  • Yes sir tbl_user is my table name. thank you sir @Bizley now its work, i created a model same name with my table. – Dulf Feb 13 '17 at 07:05

1 Answers1

4

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';
}
sxn
  • 157
  • 1
  • 7