Laravel php artisan migrate:刷新语法错误

时间:2015-12-22 14:03:14

标签: php laravel-5 syntax-error

这是代码:

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')->refrences('id')->on('users')->onDelete('cascade');
        });

错误:

  

[Illuminate \ Database \ QueryException] SQLSTATE [HY000]:一般错误:   1附近")":语法错误(SQL:创建表"文章"(" id"   integer not null主键自动增量," user_id"不是   null," title" varchar not null," body" text not null," created_at"
  datetime not null," updated_at" datetime not null," published_at"   datetime not null,外键(" user_id")引用" users"()on   删除级联))

     

[PDOException] SQLSTATE [HY000]:一般错误:1附近")":语法   错误

有什么想法吗?

1 个答案:

答案 0 :(得分:2)

这是您可以使用引用而不是引用

的错字错误
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');
        });