显示错误,如SQLSTATE [42S02]:找不到基表或视图:

时间:2018-04-14 12:11:47

标签: php node.js laravel

我想在laravel中将数据添加到laravel中,当我提交数据时显示错误(SQLSTATE [42S02]:找不到基表或视图:1146表' donation.phone_no' doesn&#39 ; t存在(SQL:选择count(*)作为phone_no的聚合,其中phone_no = 03167777777))donation.phone_no'不是fount但是我的表名是成员这是我的迁移我在谷歌搜索了几次,但无法找到合适的解决方案。任何身体帮助

public function up()
    {
        Schema::create('member', function (Blueprint $table) {
            $table->increments('id', true);
            $table->string('name', 60);
            $table->string('father_name', 60);
            $table->string('cnic_no', 60);
            $table->string('phone_no', 60);
            $table->timestamps();
            $table->softDeletes();
        });
    }

这是我的控制器

public function store(Request $request)
    {
        $this->validateInput($request);
         Member::create([
            'name' => $request['name'],
            'father_name' => $request['father_name'],
            'cnic_no' => $request['cnic_no'],
            'phone_no' => $request['phone_no'],
        ]);

        return redirect()->intended('member');
    }

2 个答案:

答案 0 :(得分:1)

默认情况下,laravel的命名约定是表名的小写复数。您的表格为member,您需要将其设为members或在模型中明确设置表格名称Member

答案 1 :(得分:0)

它似乎是模型中的问题。 您将表格名称用作 捐赠 的位置。而不是成员。 请确保您的会员模型中具有相同的表格,您将使用该表格。 可能请分享您的会员模型。

 protected $table = 'member';

该模型的完整示例如下。

namespace App;

use Illuminate\Database\Eloquent\Model;

class Member extends Model
{
    protected $table = 'member';
    protected $fillable = [
      ];
}

确保您在 config / database.php .env(环境)文件中定位正确的数据库。 如果正确的话请尝试命令。

php artisan config:clear
php artisan config:cache