首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >SQLSTATE[42S02]:未找到基表或视图: 1146表'hr.staff‘不存在

SQLSTATE[42S02]:未找到基表或视图: 1146表'hr.staff‘不存在
EN

Stack Overflow用户
提问于 2021-11-10 03:31:38
回答 1查看 1.1K关注 0票数 1

大家好!我想做CRUD,但提交表单时出错了。错误显示"SQLSTATE42S02:基表或视图未找到: 1146表'hr.staff‘不存在“。下面显示了我的数据库结构和代码。

员工模型:-

代码语言:javascript
运行
复制
    class Staffs extends Model
{
    use HasFactory;

    protected $fillable = [
        'name', 'staffid', 'address', 'religion', 'email', 'phonenum', 'maritalstatus'
    ];
}

工作人员迁移表:-

代码语言:javascript
运行
复制
public function up()
{
    Schema::create('staffs', function (Blueprint $table) {
        $table->id();
        $table->timestamps();
        $table->string('name');
        $table->integer('staffid');
        $table->string('address');
        $table->string('religion');
        $table->string('email')->unique();
        $table->integer('phonenum');
        $table->string('maritalstatus');
    });
}

StaffContoller:-

代码语言:javascript
运行
复制
public function store(Request $request)
{
    $request->validate([
        'name' => 'required',
        'staffid' => 'required',
        'address' => 'required',
        'religion' => 'required',
        'email' => 'required',
        'phonenum' => 'required',
        'maritalstatus' => 'required',
    ]);

    Staff::create($request->all());
 
    return redirect()->route('staffs.index')
                    ->with('success','Staff data has been created successfully.');
}

addstaff.blade.php:-

代码语言:javascript
运行
复制
<form method="POST" action="{{ route('staffs.store') }}">
                    @csrf
                    <div class="grid grid-cols-2 gap-6">
                        <div class="grid grid-rows-2 gap-6">
                            <div>
                                <x-label for="name" :value="__('Name:')" />
                                <x-input id="name" class="block mt-1 w-full" type="text" name="name" value="{{ old('name') }}" autofocus />
                            </div>

                            <div>
                                <x-label for="staffid" :value="__('Staff ID:')" />
                                <x-input id="staffid" class="block mt-1 w-full" type="integer" name="staffid" value="{{ old('staffid') }}" autofocus />
                            </div>

<div class="flex items-center justify-end mt-4">
                            <x-button class="ml-3">
                                {{ __('Submit') }}
                            </x-button>
                        </div>

不能粘贴完整的提交形式,但是所有的字段都在那里。

数据库结构:-

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-11-10 03:35:18

您的表名是staffs,而不是staff

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'hr.staff' doesn't exist

将模型的$table属性更新为正确的表名,然后您应该能够使用该模型创建记录。Staff::create($request->all());

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69907671

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档