简体   繁体   中英

How can I change a default db table name in Yii2?

I'm new to Yii2, and I'm trying to toy some with the advanced template. My problem is I'm getting an error when I try to signup or login on default page, and I don't know where to register the correct table name.

**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

I have already created models and controllers using Yii, and, as far as I know, it's all OK. My question is: how can I change that "user" table name to the one on my database? I have already changed the tableName() method on the ActiveRecord extended class.

class Usuario extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'usuario';
    }
...

Yii2 has a built in user model which extends active records and implements identity interface. Set your new table name there.

In common\\models\\User.php

 class User extends ActiveRecord implements IdentityInterface
  {

      public static function tableName()
      {
         return 'new_tbl_name';
      }
  ........

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM