How to Fix Unknown Database Error When Migrate Database Using Doctrine/DBAL?

559 Views Asked by At

I tried to make a POS system in migration relationship. I used Doctrine/DBAL before running migrate for making the relationship. After installing Doctrine/DBAL when I run migrate an unknown database error appears. How to fix this error?

This is Laravel 5, running error when I run migrate:

Illuminate\Database\QueryException  : SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that  Illuminate\Database\QueryException  : SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corre
sponds to your MariaDB server version for the right syntax to use near ') on delete cascade on update cascade' at line 1 (SQL: alter table `products` add constrai
nt `products_category_id_foreign` foreign key (`category_id`) references `categories` () on delete cascade on update cascade)

  at D:\laravel\POS_latihan\vendor\laravel\framework\src\Illuminate\Database\Connection.php:665
    661|         // If an exception occurs when attempting to run a query, we'll format the error
    662|         // message to include the bindings with SQL, which will make this exception a
    663|         // lot more helpful to the developer instead of just the database's errors.
    664|         catch (Exception $e) {
  > 665|             throw new QueryException(
    666|                 $query, $this->prepareBindings($bindings), $e
    667|             );
    668|         }
    669| 

  Exception trace:

  1   Doctrine\DBAL\Driver\PDOException::("SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that cor
responds to your MariaDB server version for the right syntax to use near ') on delete cascade on update cascade' at line 1")
      D:\laravel\POS_latihan\vendor\doctrine\dbal\lib\Doctrine\DBAL\Driver\PDOConnection.php:63

  2   PDOException::("SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your Mari
aDB server version for the right syntax to use near ') on delete cascade on update cascade' at line 1")
      D:\laravel\POS_latihan\vendor\doctrine\dbal\lib\Doctrine\DBAL\Driver\PDOConnection.php:61

  Please use the argument -v to see more details.
1

There are 1 best solutions below

0
On

In the Laravel path, go to config/database.php and find:

'engine' => null',

And change it to:

'engine' => 'InnoDB ROW_FORMAT=DYNAMIC',

If this doesn't solve your problem, delete your database and create a new database.