Php 雄辩的寻找错误的专栏

Php 雄辩的寻找错误的专栏,php,laravel,eloquent,Php,Laravel,Eloquent,我的迁移 Schema::create('tickets', function(Blueprint $table) { $table->increments('id'); $table->text('subject'); $table->text('body'); $table->integer('author_id')->unsigned(); $table->times

我的迁移

Schema::create('tickets', function(Blueprint $table)
    {
        $table->increments('id');
        $table->text('subject');
        $table->text('body');
        $table->integer('author_id')->unsigned();
        $table->timestamps();

    });

    Schema::table('tickets', function($table)
    {
        $table->foreign('author_id')->references('id')->on('users');
    });
关系

public function createdTickets()
{
    return $this->hasMany('App\Ticket');
}


 public function author(){
    return $this->belongsTo('App\User', 'author_id');
}
存储方法

    public function store(TicketRequest $request)
{
    $ticket = new Ticket($request->all());
    Auth::user()->createdTickets()->save($ticket);

    return redirect('tickets');
}
当我试图保存一张新的票证时,我收到了这个错误

Connection.php第624行中的QueryException: SQLSTATE[HY000]:一般错误:1表tickets没有名为user\u id的列(SQL:插入到“tickets”(“主题”、“正文”、“user\u id”、“更新的位置”、“创建的位置”)


除了关系,我还需要在哪里指定FK?

您需要在两种关系方法中指定所需的列名

public function createdTickets()
{
    return $this->hasMany('App\Ticket', 'author_id');
}

这个错误不是说您试图将数据存储到
Tickets
表中不存在的
user\u id
列吗?是的,它确实不存在,但我指定了eloquent使用另一列$this->belongsTo('App\user',author\u id');