Postgresql Yii2与树后连接
我尝试了yii2和postgres数据库,但当我尝试查询我的表时,我得到了一个错误。如何解决这个问题 我的错误链接:Postgresql Yii2与树后连接,postgresql,yii2,Postgresql,Yii2,我尝试了yii2和postgres数据库,但当我尝试查询我的表时,我得到了一个错误。如何解决这个问题 我的错误链接: 我的数据库连接的链接: 可能您没有在连接字符串上设置defaultSchema return [ 'class' => 'yii\db\Connection', 'dsn' => 'pgsql:host=localhost;dbname=db_name', 'username' => 'db_username', '
我的数据库连接的链接:
可能您没有在连接字符串上设置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
];
或
像这样更改模型中的tableName()
函数
/**
* @inheritdoc
*/
public static function tableName()
{
return 'schemaName.table_name';
}
可能您没有在连接字符串上设置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
];
或
像这样更改模型中的tableName()
函数
/**
* @inheritdoc
*/
public static function tableName()
{
return 'schemaName.table_name';
}
数据库中没有tbl_用户?!!您是否创建了名为
tbl\u user
的模型?还是你的桌子名?如果这是一个模型,那么它就不存在了,这就是为什么会出现错误。如果这应该是表名,请返回并阅读有关ActiveRecord的信息。是的,先生tbl_user是我的表名。谢谢@Bizley先生现在它的工作,我创建了一个与我的表同名的模型。数据库中没有tbl_用户?!!您是否创建了名为tbl\u user
的模型?还是你的桌子名?如果这是一个模型,那么它就不存在了,这就是为什么会出现错误。如果这应该是表名,请返回并阅读有关ActiveRecord的信息。是的,先生tbl_user是我的表名。谢谢你,先生@Bizley现在它的工作,我创建了一个与我的表同名的模型。