我一直在尝试使用laravel中的references()方法创建外键一个小时,并收到类似“找不到方法引用Illuminate \ Support \ Fluent”的错误。
这是我的代码
{
Schema::create('posts', function (Blueprint $table) {
$table->increments('id');
$table->unsignedInteger('user_id');
$table->unsignedInteger('category_id');
$table->string('title',128);
$table->longText('content');
$table->string('thumbnail_path',128);
$table->string('status',32)->default('draft');
$table->timestamps();
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->foreign('category_id')->references('id')->on('categorise')->onDelete('cascade');
});
}