[英]How can I change a default db table name in Yii2?
我是Yii2的新手,我正在尝试使用高级模板制作玩具。 我的问题是,当我尝试在默认页面上注册或登录时遇到错误,并且我不知道在哪里注册正确的表名。
**Caused by: PDOException**
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'xxx.user' doesn't exist
in xxx\...\yii2\advanced\vendor\yiisoft\yii2\db\Command.php at line 398
我已经使用Yii创建了模型和控制器,据我所知,一切正常。 我的问题是:如何将“用户”表名更改为数据库中的那个? 我已经更改了ActiveRecord扩展类的tableName()
方法。
class Usuario extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'usuario';
}
...
Yii2具有内置的用户模型,该模型扩展了活动记录并实现了身份接口。 在此处设置新表名。
在common \\ models \\ User.php中
class User extends ActiveRecord implements IdentityInterface
{
public static function tableName()
{
return 'new_tbl_name';
}
........
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.