Sqlstate[42S22]: Column Not Found: 1054 Unknown Column - Laravel

Laravel : SQLSTATE[42S22]: Column not found: 1054 Unknown column

The error is self explanatory, there is no column with name services_product_id present in services_products table. That's why it is showing the error.

I think the column name in condition is like services_products.id because generally we join table on there primary column and its primary column is id

Laravel error SQLSTATE[42S22]: Column not found: 1054 Unknown column 'categoria_id' in 'field list'

A few things, first as you said, 'Categoria' and 'Noticia' are many-To-many, so both sides should be belongsToMany.

So for your Noticia model:

public function categorias(){ 
return $this->belongsToMany(Categoria::class);
}

And the error is telling you that you do not have the 'categoria_id' in your Noticia table which is true.

So what you need to do is that.

Remove this line from the migration.

'categoria_id'=> factory(\App\Categoria::class),

And then

factory(App\Noticia::class, 100)->create()->each(function($n) {
$n->categorias()->save(factory(App\Categoria::class)->make());
});

This should work.

sqlstate[42s22]: column not found: 1054 unknown column 'description' in 'field list'

You are missing it from the migration, please add

 
$schema->string('description')->nullable()

inside your database migration file located in database/migrations/<date_and_table_name>.php and run php artisan migrate:refresh or equivalent database migration command again.

PDOException:SQLSTATE[42S22]:Column not found: 1054 Unknown column 'tbl_destinations.id' in 'where clause' in /var/www/html/...Connection.php:338

Your code looks good to me.

Try setting this in your Destination Model:

protected $primaryKey = 'des_id';

SQLSTATE[42S22]: Column not found: 1054 Unknown column - Laravel

You have configured the auth.php and used members table for authentication but there is no user_email field in the members table so, Laravel says

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'user_email' in
'where clause' (SQL: select * from members where user_email = ? limit
1) (Bindings: array ( 0 => 'test@hotmail.com', ))

Because, it tries to match the user_email in the members table and it's not there. According to your auth configuration, laravel is using members table for authentication not users table.

Laravel 5.8: SQLSTATE[42S22]: Column not found: 1054 Unknown column

the find method only works on id so it's better to use where clause

$user_wallet = UserWallet::where('user_id', $us_id);

SQLSTATE[42S22]: Column not found: 1054 Unknown column '0' in 'where clause' in laravel

you sould use :

testQuestion::updateOrCreate(['question_id' => $request->questions[$key]['question_id']],$input)

instead of :

testQuestion::updateOrCreate(['question_id',$request->questions[$key]['question_id']],$input);

SQLSTATE[42S22]:Column not found:1054 Unknown column'tabl_name.id' in'where clause'select*from`tabl_name`where'tabl_name`.`id`=16

You won't be able to use the find or findOrFail if you don't use the standard naming convention for the identifier as laravel expects which is id. findOrFail expects the primary key to be named "id".

Because your primary key is named "des_id", for you to have the same exception behavior, you should use the where clause then end it with the firstOrFail() method which will offer a similar behavior to findOrFail.

You can learn more about findOrFail and firstOrFail here.

This is how you should perform that call to have the same Not Found Exception handling as findOrFail.

$destination_id = Destination::where('des_id','=',$request->destination_id)->firstOrFail();


Related Topics



Leave a reply



Submit