SQLSTATE[42S02]: Base table or view not found: 1146 Table

Asked

Viewed 11,090 times

5

I’ve got this little problem in Laravel. The good old problem with the S that Laravel puts in the end. I have researched in innumerable foruns but the given solution does not work.

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'cautofacil.fornecedors' doesn’t exist (SQL: select * from fornecedors)

The TABLE in Mysql is CALLED SUPPLIERS

>     <?php
> 
> use Illuminate\Database\Schema\Blueprint; use
> Illuminate\Database\Migrations\Migration;
> 
> class CreateFornecedoresTable extends Migration {
> 
>     
>     /**
>      * Run the migrations.
>      *
>      * @return void
>      */
>     
>     protected $table = "fornecedores";
>     
>     public function up() {

I’ve given Protect on the table and yet it keeps putting the S maledit at the end. Can someone give me a light please?

Thank you very much

  • 2

    Enter the model code.

  • Check table name with database name may be wrong

3 answers

5


Is not in the Migration who does this, is in Model.

Open the created Model. Probably, Providers.php.

Puts:

protected $table = "fornecedores";

And forehead.

Documentation

https://laravel.com/docs/4.2/eloquent#basic-Usage

class User extends Eloquent {

    protected $table = 'my_users';

}

Works only for tables named in English.

1

Friends, this problem happened to me because I tried to make a separate form request and calling it in place of the request, finally the model with eloquent database did not accept because it is an authentication model so it will not accept a separate form request the validation will have to be in the method itself. Ex:

public function update(UserRequest $request, $id)
{
  // Não vai aceitar
}

It will have to be so

public function update(Request $request, $id)
{
  // Vai aceitar
}

1

He had the same problem and solved!

class Annotation extends Model
{

   protected $table = "annotation";
   protected $fillable = ['titulo','message'];

}

Thank you!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.