【问题标题】:Table is existed but getting error SQLSTATE[42S02]: Base table or view not found: 1146 Table 'exyz.input_fields' doesn't exist表存在但出现错误 SQLSTATE [42S02]:未找到基表或视图:1146 表“exyz.input_fields”不存在
【发布时间】:2020-01-05 13:27:36
【问题描述】:

我正在尝试从 laravel 播种机插入值。插入了所有其他表数据,但我被困在 input_fields 表上。即使它在我的本地 Mamp 服务器上运行也非常好,但是当我尝试在 Live 服务器上运行时出现错误,但我看到表名存在于我的数据库中。我也运行“composer dumpautoload”,但仍然面临同样的问题。

inputField.php

namespace App;

use Illuminate\Database\Eloquent\Model;

class inputField extends Model
{
    protected $table = 'input_fields';

    public function dropDown()
    {
        return $this->belongsTo('App\dropDown', 'drop_id');
    }
}

2017_10_13_093801_input_Fields

Schema::create('input_Fields', function (Blueprint $table) {
            $table->increments('id');
            $table->string('field_name');
            $table->string('cat_id');
            $table->string('description');
            $table->string('drop_id')->nullable();
            $table->rememberToken();
            $table->timestamps();
        });

InputFieldsTableSeeder.php

        $inputvalue = new inputField();
        $inputvalue->field_name = 'Bilirubin Total';
        $inputvalue->cat_id = '1';
        $inputvalue->description = '0.0 - 1.2';
        $inputvalue->save();

【问题讨论】:

  • 看起来你的字母大小写有点不一致。 $table = 'input_fields'create('input_Fields', ...。我不知道 Laravel 是否在您创建表时将名称标准化为较低,但如果不是,那可能是一个问题。不同的环境/配置可以有不同的表名区分大小写设置。尝试保持一致(更改为create('input_fields', ...),看看是否效果更好。
  • 那么,这是成功还是错误仍然存​​在?
  • 非常感谢。这对我来说非常有用。但是你能告诉我为什么它在本地之前工作而不是在实时服务器上工作。 :-)。
  • 就像我在第一条评论中所说:“不同的环境/配置可以有不同的表名区分大小写设置”
  • 我发布了一个答案。随意接受它,以便其他人知道问题已得到解决。

标签: php mysql laravel-5 migration laravel-seeding


【解决方案1】:

你的字母大小写有点不一致。

$table = 'input_fields' 

create('input_Fields', .... 

不同的环境/配置可以有不同的表名区分大小写设置。尝试并保持一致并更改为

create('input_fields', ...) 

它应该会更好。

【讨论】:

    猜你喜欢
    • 2021-12-22
    • 2018-04-19
    • 2015-10-05
    • 2018-06-30
    • 2021-05-13
    • 2021-10-17
    • 2020-04-28
    • 2015-09-22
    • 2016-03-03
    相关资源
    最近更新 更多