2017-02-13 31 views
0

我試過yii2和postgres數據庫,但是當我嘗試查詢我的表時,我得到了一個錯誤。如何解決這個問題?我的錯誤Yii2和postgres connecttion

LINK: Screenshot


鏈接指向我的數據庫連接:

Screenshot

+0

您沒有** ** tbl_user數據庫中?! –

+0

您是否創建了名爲'tbl_user'的模型?或者它是你的表名?如果這是模型而不是它,那就是爲什麼你有錯誤。如果這應該是表名回到[指南](http://www.yiiframework.com/doc-2.0/guide-db-active-record.html)並閱讀有關ActiveRecord。 – Bizley

+0

是的,先生tbl_user是我的表名。謝謝先生@Bizley現在的工作,我創建了一個與我的表同名的模型。 – DULF

回答

1

也許你不設置defaultSchema在連接字符串

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

或 更改tableName()函數模型這樣

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