在Laravel迁移中,我有以下一行:
$table->tinyInteger('action_type')->index();
并且当我尝试使用以下代码将数据保存在表中时:
ActionsLog::create([
'account_id' => auth()->user()->id,
'action_type' => 1, //like
'log', $ex->getMessage()
]);
laravel无法返回名称为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();
});
}
答案 0 :(得分:4)
问题出在第'log', $ex->getMessage()
行。将此行中的,
更改为=>
。将代码替换为:
ActionsLog::create([
'account_id' => auth()->user()->id,
'action_type' => 1,
'log' => $ex->getMessage()
]);
答案 1 :(得分:0)
您应该像那样创建
ActionsLog::create([
'account_id' => auth()->user()->id,
'action_type' => 1,
'log'=> $ex->getMessage()
]);