我有一个包含用户用户名、密码和其他信息的表用户数据库,我成功地将我的yii2项目连接到了数据库,并能够获取一些数据,但当我尝试使用表用户中存在的用户名和密码之一登录时,yiiDebugger给了我这个例外:
Database Exception – yii'db'Exception
SQLSTATE[42P01]: Undefined table: 7 ERROR: relation "user" does not exist
LINE 1: SELECT * FROM "user" WHERE ("username"=$1) AND ("status"=$2)
我的表名为users,但在查询中它似乎是user。我该怎么修?
是否重命名了表?检查模型方法tableName()
class User extends 'yii'db'ActiveRecord
{
public static function tableName()
{
return 'users';
}
}
使用
$user->findOne(['username'=>$username, 'password'=>$password])