Php 显示类似SQLSTATE[42S02]的错误:找不到基表或视图:
当我提交数据时,我想将数据添加到laravel中的数据库中,它会显示一个错误,如(SQLSTATE[42S02]:找不到基表或视图:1146表“捐赠.电话号码”不存在(SQL:选择count(*)作为聚合自Php 显示类似SQLSTATE[42S02]的错误:找不到基表或视图:,php,node.js,laravel,Php,Node.js,Laravel,当我提交数据时,我想将数据添加到laravel中的数据库中,它会显示一个错误,如(SQLSTATE[42S02]:找不到基表或视图:1146表“捐赠.电话号码”不存在(SQL:选择count(*)作为聚合自电话号码其中电话号码=031677777))捐款。电话号码不是fount但我的表名是members这是我的迁移我在谷歌搜索了好几次,但找不到合适的解决方案。有人帮忙吗 public function up() { Schema::create('member', fun
电话号码
其中电话号码
=031677777))捐款。电话号码不是fount但我的表名是members这是我的迁移我在谷歌搜索了好几次,但找不到合适的解决方案。有人帮忙吗
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');
}
默认情况下,laravel的命名约定是表名的小写复数形式。您的表是
成员
您需要使其成为成员
或在模型中明确设置表名成员这似乎是模型中的问题。
将表名用作捐赠的位置。而不是成员。
请确保在您的成员模型中有和您将要使用的表相同的名称。
可能的话,请分享你的会员模式
protected $table = 'member';
模型的完整示例如下
namespace App;
use Illuminate\Database\Eloquent\Model;
class Member extends Model
{
protected $table = 'member';
protected $fillable = [
];
}
确保在config/database.php和.env(environment)文件中针对正确的数据库。
如果正确,请尝试命令
php artisan config:clear
php artisan config:cache
我添加了成员,但它认为phone_no列是tabel,而不是members Base table或view not found:1146 table'generation.phoe_no'在phoe_no中不存在不是tabel它是column table name是members请发布您的模型成员
请确保您没有使用任何多对多关系进行捐赠?好吗确保您的database.php和env针对的是正确的数据库?当我编辑表单时,它会显示错误SQLSTATE[42S02]:找不到基表或视图:1146表'generation.cnic'不存在cnic不是表