【问题标题】:SQLSTATE[42S02]: Base table or view not found: 1146 Table 'db_wls.users' doesn't exist on laravel 5.2SQLSTATE [42S02]:未找到基表或视图:1146 表 'db_wls.users' 在 laravel 5.2 上不存在
【发布时间】:2016-08-31 17:50:05
【问题描述】:

问题: SQLSTATE [42S02]:未找到基表或视图:1146 表 'db_wls.users' 不存在(SQL:从users 中选择计数(*)作为聚合,其中email = onlynadim0000@gmail.com)

模型类

<?php namespace App;

use Illuminate\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;

class User extends Model implements AuthenticatableContract, CanResetPasswordContract {

    use Authenticatable, CanResetPassword;

    /**
     * The database table used by the model.
     *
     * @var string
     */
    public $table = 'user';

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = ['first_name','last_name', 'email', 'password','address','city_id'];

    /**
     * The attributes excluded from the model's JSON form.
     *
     * @var array
     */
    protected $hidden = ['password', 'remember_token'];


    public function voucher()
    {
        return $this->hasOne('App\Voucher');
    }

    public function getFullName()
    {
        return ucfirst(implode(" ",[$this->usr_firstname,$this->usr_lastname]));
    }

}

虽然用户表确实存在于数据库中。 为什么会显示此错误。

提前致谢

【问题讨论】:

  • 错误很明显。表users 不存在。
  • 是的,但请阅读模型
  • 很明显模型包含不同的表名。但是没有提供表明模型导致错误的代码。
  • 我提到了模型上的表名。这应该可以
  • 您提到 $table="user" 将其更改为用户。查看您的模型类代码

标签: php authentication eloquent laravel-5.2


【解决方案1】:

您可以在模型中覆盖它。

公共 $table = '用户'

【讨论】:

    【解决方案2】:

    检查您的数据库。没有名为“用户”的此类表,因此出现错误。

    【讨论】:

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