【问题标题】:SQLSTATE[42S02]: Base table or view not found: 1146 Table '***.indices' doesn't exist laravelSQLSTATE [42S02]:未找到基表或视图:1146 表 '***.indices' 不存在 laravel
【发布时间】:2022-03-23 13:21:07
【问题描述】:

我有表格索引页,但仍然有这个错误!这是我的代码:

   public function up()
    {
        Schema::create('index', function (Blueprint $table) {
            $table->increments('id');
            $table->text('about');
            $table->string('video');
            $table->timestamps();
        });
    }

型号:

class Index extends Model
{
    protected $fillable = [
        'about' ,'video'
    ];
}

索引从何而来?

【问题讨论】:

  • 请发布您的模型,您是否按模型调用它?
  • 我已经编辑过了
  • 我已经发布了答案

标签: php laravel


【解决方案1】:

按照约定,“snake case”,类的复数名称将用作表名,除非明确指定另一个名称。

在您的索引模型中,您需要明确指定表名

class Index extends Models {
    protected $table = 'index';
    ...
}

【讨论】:

  • @hadis 不客气。如果有帮助,请采纳答案。
【解决方案2】:

indices 是“索引”的复数形式。默认情况下,laravel 会查找模型的复数形式。例如,App\User 指的是users 表。 这就是约定。

'***.indices' 未找到,但您的架构类(迁移)正在创建“索引”表。

在您的模型中添加以下内容。应该可以正常工作。

protected $table = 'index';

【讨论】:

    猜你喜欢
    • 2018-03-16
    • 2020-06-26
    • 2016-07-15
    • 2016-01-19
    • 1970-01-01
    • 1970-01-01
    • 2021-12-22
    • 2018-04-19
    • 2015-10-05
    相关资源
    最近更新 更多