Base table or view not found: 1146 Table Laravel 5

Stefan Izdrail

Founder & Senior Architect · 2026-06-29

Laravel Company
Title: Resolving "Base Table or View not Found" Errors in Laravel 5 when Saving Data to MySQL Body:

You are encountering the issue "Base table or view not found: 1146 Table 'sistemal5.cotizacions' doesn't exist (SQL: insert into `cotizaciones` (`customer_id`, `total`, `updated_at`, `created_at`) values (1501, 150.69, 2015-05-11 03:16:25, 2015-05-11 03:16:25))" when attempting to save data to MySQL using Laravel 5, but other forms and save() methods work fine. You might be making a simple mistake that is hindering the correct querying of your model table in the database.

Investigate the Table Name and Database Connection

Firstly, verify that you are using the correct table name. In this case, 'cotizaciones' instead of 'cotizacions'. Ensure that both your code and database tables adhere to the same naming convention for consistency. It could be a typo or an incorrect configuration in the connection.

Check Your Model Configuration

Secondly, review your model configuration to verify if the correct table name is specified. If it is not, update its name accordingly:
class Cotizacion extends Model {

    protected $table = 'cotizaciones'; // Assuming that is the correct table name

}
Alternatively, you can use the 'connection' parameter within your model to specify a connection other than the default one. This could be useful if there are multiple databases on your system:
class Cotizacion extends Model {

    protected $table = 'cotizaciones';
    protected $primaryKey = 'id_cotizacion'; // Ensure you define a primary key appropriately for the table
    protected $connection = 'myCustomConnection' // Specify your desired connection name here

}

Ensure Your Model Mapping Matches Your Database Structure

Ensure that your model map attributes to the relevant fields in your database tables. In this case, you are adding customer_id, total, updated_at and created_at values to the cotizaciones table. Check your model to ensure these attributes align with the table columns. Consider using the 'timestamps' trait if you wish to automatically maintain updated_at and created_at fields during querying:
class Cotizacion extends Model {

    protected $table = 'cotizaciones';
    protected $primaryKey = 'id_cotizacion'; // Specify your primary key appropriately
    use Timestamps; // Include timestamps trait for automatic timestamp management
    protected $fillable = [
        'customer_id',
        'total'
    ]; // Define the fields you want to fill automatically when creating a new model instance

}

Use Appropriate Data Types and Validation Rules in Your Request Class

Ensure that your data types and validation rules in your request class are correct. Verify if the values you are passing to your store method are of the right type as per the table attributes' data type specifications:
public function store(CotFormRequest $request) {
    $quote = new Cotizacion;
    $quote->customer_id = Input::get('data.clientid'); // Verify that this is an integer value
    $quote->total = Input::get('data.totalAftertax'); // Verify that this is a valid numeric value without any extra characters
    $quote->save();
}

Check Your Database Configuration and Connection

Lastly, examine your database configuration and connection settings. Make sure you're using the right database name and credentials in your .env file:
.env
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel_database
DB_USERNAME=root
DB_PASSWORD=password

Conclusion

Remember that Laravel provides excellent documentation covering common issues like this. It is essential to refer to the official sources for guidance on troubleshooting problems with Laravel and MySQL interactions. By following these steps, you should be able to resolve your issue and avoid similar errors in the future.