Laravel 5.6 running on: PHP 7.2, MariaDB 10.3
When I want to set foreign key for my table, I just keep taking that error.
On other tables, all id variables defined by Laravel itself and auto increments unsigned
So, my Migration is like this:
public function up()
{
Schema::create('user_roles', function (Blueprint $table) {
$table->increments('id');
$table->unsignedInteger('role_id');
$table->unsignedInteger('user_id');
$table->foreign('role_id')->references('id')->on('roles')->onDelete('cascade');
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
});
}
The error is like this:
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 ') on delete cascade' at lin e 1 (SQL: alter table
user_roles
add constraintuser_roles_role_id_foreign
foreign key (role_id
) referencesroles
() on delete cascade)
Errors thrown by Laravel:
1 PDOException::("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 ') on delete cascade' at line 1") C:\xampp\htdocs\order-project\vendor\laravel\framework\src\Illuminate\Database\Connection.php:452
2 PDO::prepare("alter table
user_roles
add constraintuser_roles_role_id_foreign
foreign key (role_id
) referencesroles
() on delete cascade") C:\xampp\htdocs\order-project\vendor\laravel\framework\src\Illuminate\Database\Connection.php:452