英文:
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!
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论