我正在学习laracast上的laravel 5教程,我收到了这个错误。
异常"PDOException",消息为"SQLSTATE[HY000]:一般错误:1靠近")":
Schema::create('articles', function(Blueprint $table)
{
$table->increments('id');
$table->Integer('user_id')->unsigned();
$table->string('title');
$table->text('body');
$table->timestamps();
$table->timestamp('published_at');
$table->foreign('user_id')
->refrences('id')
->on('users')
->onDelete('cascade');
});
您在"refracts('id)"上有一个拼写错误。您的迁移应该是这样的:
<?php
use Illuminate'Database'Schema'Blueprint;
use Illuminate'Database'Migrations'Migration;
class Test extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('articles', function(Blueprint $table)
{
$table->increments('id');
$table->integer('user_id')->unsigned();
$table->string('title');
$table->text('body');
$table->timestamps();
$table->timestamp('published_at');
$table->foreign('user_id')
->references('id')
->on('users')
->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('articles', function(Blueprint $table){
$table->dropForeign('articles_user_id_foreign');
});
Schema::drop('articles');
}
}