Cannot insert data in Mysql SQLSTATE[42S02]: Base table or view not found: 1146 Table Laravel 8

huangapple go评论55阅读模式
英文:

Cannot insert data in Mysql SQLSTATE[42S02]: Base table or view not found: 1146 Table Laravel 8

问题

我使用的是Laravel 8,当我尝试将数据插入到MySQL数据库时,我遇到了如图所示的错误。我该如何解决这个问题?谢谢!

英文:

I am using Laravel 8, and when I try to insert data into the MySQL database, I encounter an error as shown in the image. How can I fix this issue? Thank you!

enter image description here

enter image description here

enter image description here

Hello, I am using Laravel 8, and when I try to insert data into the MySQL database, I encounter an error as shown in the image. How can I fix this issue? Thank you!

答案1

得分: 1

错误出现在您的截图中提到的地方,是因为您对 tendanhmuc 字段进行的验证规则为 'required|unique:tendanhmuc|max:255'

Laravel 的唯一验证正在搜索您的数据库中的表 tendanhmuc,但该表不存在。

解决方法: 请将您对 tendanhmuc 字段的验证规则替换为以下代码。

'tendanhmuc' => 'required|unique:danhmuc,tendanhmuc|max:255'

Laravel 有许多用于使用唯一验证的语法。了解更多关于 laravel 唯一验证 的信息。

英文:

Error which is mentioned in your screenshots is coming because of your validation of 'tendanhmuc'=>'required|unique:tendanhmuc|max:255'

laravel unique validation is searching for table tendanhmuc in your database. But it does not exist.

Solution: Replace your validation rule for tendanhmuc field with below code.

'tendanhmuc'=>'required|unique:danhmuc,tendanhmuc|max:255'

There are many syntax of laravel to use unique validation. Read more about laravel unique validation.

huangapple
  • 本文由 发表于 2023年6月15日 15:34:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/76480130.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定