SQLSTATE [42S22]:找不到列:1054 未知列 laravel 5.1
Posted
技术标签:
【中文标题】SQLSTATE [42S22]:找不到列:1054 未知列 laravel 5.1【英文标题】:SQLSTATE[42S22]: Column not found: 1054 Unknown column laravel 5.1 【发布时间】:2017-04-03 16:31:30 【问题描述】:我有这个查询异常
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'updated_at' in 'field list' (SQL: insert into `comentarios` (`NombreUsuario`, `CorreoUsuario`, `TelefonoUsuario`, `Asunto`, `Mensaje`, `FecComentario`, `updated_at`, `created_at`) values (Andres, poc@dw.xom, 124422432, Andres es genial, vffgdf, 2016-11-20 03:34:45, 2016-11-20 03:44:18, 2016-11-20 03:44:18))
这是我用于 laravel 5.1 的 sql
public function store(Request $request)
\JuanSapo\ContadorT::create([
'NombreUsuario' => $request['nombres'],
'CorreoUsuario' => $request['email'],
'TelefonoUsuario' => $request['numContacto'],
'Asunto' => $request['asunto'],
'Mensaje' => $request['mensaje'],
'FecComentario' => $request['fecha']
]);
return view('contacto');
我可以看到,我最后还有两个日期,这个看看我的sql的错误,
这是我的 auth.php
<?php
return [
'driver' => 'eloquent',
'model' => JuanSapo\User::class,
'model' => JuanSapo\ContadorT::class,
'table' => 'users',
'table' => 'comentarios',
'password' => [
'email' => 'emails.password',
'table' => 'password_resets',
'expire' => 60,
],
];
这是我的 User.php
<?php
namespace JuanSapo;
use Illuminate\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Foundation\Auth\Access\Authorizable;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
class User extends Model implements AuthenticatableContract,
AuthorizableContract,
CanResetPasswordContract
use Authenticatable, Authorizable, CanResetPassword;
protected $table = 'users';
protected $fillable = ['name', 'email', 'password'];
protected $hidden = ['password', 'remember_token'];
这是我的 contadotT.php
<?php
namespace JuanSapo;
use Illuminate\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Foundation\Auth\Access\Authorizable;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
class ContadorT extends Model implements AuthenticatableContract,
AuthorizableContract,
CanResetPasswordContract
use Authenticatable, Authorizable, CanResetPassword;
protected $table = 'comentarios';
protected $fillable = ['NombreUsuario', 'CorreoUsuario', 'TelefonoUsuario','Asunto','Mensaje','FecComentario'];
protected $hidden = ['contador'];
【问题讨论】:
***.com/questions/28277955/…的可能重复 【参考方案1】:你必须在你的 ContadorT
模型类中添加 public $timestamps = false;
,所以 Laravel 不会在查询中添加 crated_at
和 update_at
字段
【讨论】:
是真的,谢谢以上是关于SQLSTATE [42S22]:找不到列:1054 未知列 laravel 5.1的主要内容,如果未能解决你的问题,请参考以下文章
SQLSTATE [42S22]:找不到列:1054 未知列 '0' where 子句
SQLSTATE [42S22]:找不到列:1054 未知列 laravel 5.1
SQLSTATE [42S22]:找不到列:1054 'where 子句'中的未知列'user_id'
Laravel 删除数据 - SQLSTATE [42S22]:找不到列:1054 未知列