【问题标题】:The table does not exist: {{%active_record}}该表不存在:{{%active_record}}
【发布时间】:2018-02-03 05:16:47
【问题描述】:

我是 yii 的新手,首先通过 gii 学习生成 CRUD 操作我创建了一个国家表并使用 gii 生成模型和控制器以及视图我得到以下错误 无效配置 – yii\base\InvalidConfigException 表不存在:{{%country_search}}

【问题讨论】:

  • 你是否正确连接到你的数据库并且有这个表country_search
  • 是的,我确定已连接到数据库,但我只有 country 表但没有 country_search 表实际上我只是遵循yiiframework.com/doc-2.0/guide-start-gii.html docs 的规则,请建议
  • 你需要先在你的数据库中创建这个表,然后你可以在 Yii 中使用 Gii 为它生成代码。
  • 好的先生解决了谢谢

标签: yii2 gii


【解决方案1】:

将此添加到 CountrySearch 类:

    /**
     * @inheritdoc
     */
     public static function tableName()
     {
         return 'country';
     }

【讨论】:

    【解决方案2】:

    只是添加到 temirbek 答案:

    文件模型/Country.php

    <?php
    
    namespace app\models;
    
    use yii\db\ActiveRecord;
    
    class Country extends ActiveRecord
    {
         public static function tableName()
         {
             return 'country';
         }
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-12-14
      • 2011-04-05
      • 2012-02-05
      • 2015-06-16
      • 2013-04-28
      • 2010-10-19
      • 2013-08-19
      相关资源
      最近更新 更多