Home > Database > Mysql Tutorial > Laravel 5: Why is My \'Table Not Found\' Error Happening and How Do I Fix It?

Laravel 5: Why is My \'Table Not Found\' Error Happening and How Do I Fix It?

Susan Sarandon
Release: 2024-10-26 09:29:02
Original
1014 people have browsed it

 Laravel 5: Why is My

Base Table Not Found: Troubleshooting in Laravel 5

When attempting to save data to MySQL using Laravel 5, an "1146 Table not found" error can occur. This issue arises when Laravel cannot determine the plural form of a table name, resulting in the addition of an "S" to the end of the name.

Controller and Model Configuration

Here's the provided controller store method:

<code class="php">public function store(CotFormRequest $request)
{    
    $quote = new Cotizacion;
    $quote->customer_id = Input::get('data.clientid');
    $quote->total = Input::get('data.totalAftertax');    
    $quote->save();    
}</code>
Copy after login

And the model Cotizacion:

<code class="php">namespace App\Models\Cotizacion;

use Illuminate\Database\Eloquent\Model;


class Cotizacion extends Model {

}</code>
Copy after login

Resolving the Issue

To fix this, explicitly define the table name in the model:

<code class="php">class Cotizacion extends Model{
    public $table = "cotizacion";
}</code>
Copy after login

By specifying the table name, Laravel will correctly identify it and prevent adding an extra "S".

The above is the detailed content of Laravel 5: Why is My 'Table Not Found' Error Happening and How Do I Fix It?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template