Laravel return 保存数据的数据库列名错误

Laravel return wrong column name of database to save data

在 Laravel 迁移中我有这一行:

$table->tinyInteger('action_type')->index();

当我尝试使用此代码将数据保存在 table 中时:

ActionsLog::create([
    'account_id' => auth()->user()->id,
    'action_type' => 1,  //like
    'log', $ex->getMessage()
]);

laravel 无法 return 名称为 action_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()
]);