Php Laravel返回错误的数据库列名以保存数据
在Laravel迁移中,我有这样一行:Php Laravel返回错误的数据库列名以保存数据,php,laravel,laravel-5.6,Php,Laravel,Laravel 5.6,在Laravel迁移中,我有这样一行: $table->tinyInteger('action_type')->index(); 当我尝试在表中保存数据时,如以下代码所示: ActionsLog::create([ 'account_id' => auth()->user()->id, 'action_type' => 1, //like 'log', $ex->getMessage() ]); laravel无法返回第三列
$table->tinyInteger('action_type')->index();
当我尝试在表中保存数据时,如以下代码所示:
ActionsLog::create([
'account_id' => auth()->user()->id,
'action_type' => 1, //like
'log', $ex->getMessage()
]);
laravel无法返回第三列,该列的名称为action\u type
,我收到以下错误:
Column not found: 1054 Unknown column '1' in 'field list' (SQL: insert into `actions_logs` (`account_id`, `action_type`, `1`, `updated_at`, `created_at`) values (2, 1, SQLSTATE[42S22]: Column not found: 1054 Unknown column '1' in 'field list' (SQL: insert into `actions_logs` (`account_id`, `action_type`, `1`, `updated_at`, `created_at`) values (2, 1, Use of undefined constant ture - assumed 'ture' (this will throw an Error in a future version of PHP), 2018-07-11 07:50:18, 2018-07-11 07:50:18)), 2018-07-11 07:50:18, 2018-07-11 07:50:18))
我的迁移文件:
public function up()
{
Schema::create('actions_logs', function (Blueprint $table) {
$table->increments('id');
$table->integer('account_id')->unsigned();
$table->foreign('account_id')->references('id')->on('instagram_actions_histories')->onDelete('cascade');
$table->tinyInteger('action_type')->index();
$table->text('log');
$table->timestamps();
});
}
问题在于行
'log',$ex->getMessage()
。将此行中的,
更改为=>
。将代码替换为:
ActionsLog::create([
'account_id' => auth()->user()->id,
'action_type' => 1,
'log' => $ex->getMessage()
]);
你不能那样创造
ActionsLog::create([
'account_id' => auth()->user()->id,
'action_type' => 1,
'log'=> $ex->getMessage()
]);
'log'=>$ex->getMessage()----'log',$ex->getMessage()。在第一个键中=>value,在第二个值中,value