尝试添加外键约束时会不断出错

时间:2018-08-07 18:09:58

标签: laravel eloquent

我有图书迁移文件:

   <?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateBooksTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('books', function (Blueprint $table) {
            $table->increments('id');
            $table->timestamps();
            $table->string('title');
            $table->string('Author');
            $table->text('Book_description');
            $table->integer('user_id');
            $table->foreign('user_id')->refrences('id')->on('users');
            $table->boolean('donated')->default(false);
            $table->string('country',150);
            $table->string('city',30);
            $table->string('path');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('books');
    }
}

但是当我运行以下命令时:

php artisan migrate:refresh

我收到以下错误:

  

Illuminate \ Database \ QueryException:SQLSTATE [42000]:语法错误或访问冲突:1064您的SQL语法有一个错误;请参见语法。检查与您的MySQL服务器版本相对应的手册,以找到在第1行附近的')'处使用的正确语法(SQL:修改表books添加约束books_user_id_foreign外键(user_id)引用users())

我已经搜索过Google,但是找不到错误的地方,并且我已经阅读了Laravel 5.6文档,但是我找不到错误的地方。

2 个答案:

答案 0 :(得分:2)

有一个错字:它必须是var elements = stripe.elements({ fonts: [ { family: 'Gotham Narrow A', src: 'url(https://myhostedwebsite.com/fonts/######/#################.eot)', style: 'normal', weight: '300', }, ], }); 而不是->references('id')

答案 1 :(得分:0)

尝试一下

map2_ZipList = zipWith
相关问题