异常'PDOException',消息'SQLSTATE [HY000]:一般错误:1靠近“)”laravel

时间:2015-02-16 08:59:15

标签: php laravel-5

我正在关于拉拉斯特的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');
    });

1 个答案:

答案 0 :(得分:1)

你有#34;引用错误('是)。您的迁移应如下所示:

<?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');
    }

}