Reputation: 1
I have 2 table. my code is working well on laravel 5.7 but when i using laravel. I always get error like this. anyone can help me?
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');
});
This is the error:
Illuminate\Database\QueryException : SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')' at line 1 (SQL: alter table
tb_user
add constrainttb_user_id_satuan_foreign
foreign key (id_satuan
) referencestb_satuan
())
Upvotes: 0
Views: 229
Reputation: 375
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();
});
}
Upvotes: 0
Reputation: 610
It's REFERENCES not REFERENCE
$table->foreign('id_satuan')->references('id_satuan')->on('tb_satuan');
Upvotes: 1