0

我有 2 张桌子。我的代码在 laravel 5.7 上运行良好,但是当我使用 laravel 时。我总是收到这样的错误。任何人都可以帮助我吗?

Schema::create('tb_satuan', function (Blueprint $table) {
        $table->bigIncrements('id_satuan');
        $table->string('nama_satuan',40);
        $table->timestamps();
    });

    Schema::create('tb_user', function (Blueprint $table) {
        $table->bigIncrements('id_user');
        $table->BigInteger('id_satuan')->unsigned();
        $table->string('username',20);
        $table->string('email',30);
        $table->text('password');
        $table->timestamps();

        $table->foreign('id_satuan')->reference('id_satuan')->on('tb_satuan');
    });

这是错误:

Illuminate\Database\QueryException : SQLSTATE[42000]: 语法错误或访问冲突:1064 您的 SQL 语法有错误;检查与您的 MariaDB 服务器版本相对应的手册,以在第 1 行的 ')' 附近使用正确的语法(SQL:alter table tb_useradd constraint tb_user_id_satuan_foreignforeign key ( id_satuan) references tb_satuan())

4

2 回答 2

1

这是 REFERENCE S不是 REFERENCE

$table->foreign('id_satuan')->references('id_satuan')->on('tb_satuan');
于 2019-04-02T21:06:13.557 回答
0
 public function up()
    {
        Schema::create('posts', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->unsignedBigInteger('user_id');
            $table->string('title');
            $table->string('slug')->unique();
            $table->string('image')->default('default.png');
            $table->text('body');
            $table->integer('amount');
            $table->integer('room');
            $table->boolean('status')->default(false);
            $table->foreign('user_id')
                ->references('id')->on('users')
                ->onDelete('cascade');
            $table->timestamps();
        });
    }
于 2019-11-06T05:22:39.463 回答