首页 > 解决方案 > 尝试将表单提交到数据库时出错

问题描述

嗨,所以当我尝试将表单提交到我的数据库时,我收到以下错误

错误

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'urenregistratie.issues' doesn't exist (SQL: insert into `issues` (`iname`, `begroting`, `description`, `updated_at`, `created_at`) values (test, 100, test description, 2019-12-04 09:19:54, 2019-12-04 09:19:54))

控制器

public function store(Request $request)
    {
        $this->validate($request,[
            'iname' => 'required',
            'begroting' => 'required',
            'description' => 'required',

            ]);

            $issue = new Issue;

            $issue->iname = $request->input('iname');
            $issue->begroting = $request->input('begroting');
            $issue->description = $request->input('description');

            $issue->save();

            return redirect('/issue')->with('success', 'Data Saved');



    }

移民

   public function up()
    {
        Schema::create('issue', function (Blueprint $table) {
            $table->increments('id');
            $table->string('iname');
            $table->time('begroting');
            $table->mediumText('description');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('issue');
    }
}

Urenregistratie 是我的数据库名称。但我不知道它从哪里得到问题,因为我在没有 S 的情况下称它为问题,所以它从哪里得到问题

如果我确实缺少任何代码方面的信息,请告诉我。

标签: sqldatabaselaravel

解决方案


您的迁移会创建问题表,但您要保存到问题表。检查模型类中的表名。

class Issue extends Model
{
protected $table = 'issue'; // this table name
.
.
.
}

推荐阅读