使用 Doctrine/DBAL 迁移数据库时如何修复未知数据库错误?

Posted

技术标签:

【中文标题】使用 Doctrine/DBAL 迁移数据库时如何修复未知数据库错误?【英文标题】:How to Fix Unknown Database Error When Migrate Database Using Doctrine/DBAL? 【发布时间】:2020-01-15 20:25:59 【问题描述】:

我试图在迁移关系中创建一个POS 系统。我在运行 migrate 之前使用了Doctrine/DBAL 来建立关系。安装Doctrine/DBAL 后,当我运行迁移时,出现未知的database 错误。如何解决此错误?

这是Laravel 5,我运行迁移时出错:

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】:

在Laravel路径下,进入config/database.php,找到:

'engine' => null',

并将其更改为:

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

如果这不能解决您的问题,请删除您的数据库并创建一个新数据库。

【讨论】:

以上是关于使用 Doctrine/DBAL 迁移数据库时如何修复未知数据库错误?的主要内容,如果未能解决你的问题,请参考以下文章

doctrine / dbal-尝试将字符串字段更改为日期时出错

工匠迁移错误“类'Doctrine \ DBAL \ Driver \ PDOMySql \ Driver'not found”,

工匠迁移错误“找不到类'Doctrine\\DBAL\\Driver\\PDOMySql\\Driver'”,

laravel5.1 上安装依赖(doctrine / dbal)

在作曲家 laravel 上安装依赖项(doctrine/dbal)

在 Laravel 迁移中更改列会导致异常:更改表的列需要 Doctrine DBAL