在Laravel中,使用migration作为数据库的版本控制工具,当需要对已存在的数据表作更改,需要额外引入doctrine/dbal扩展。

在一次使用中,对数据表中的某个字段的评论进行了更改,在php artisan migrate的时候,抛出一下异常:

  [Doctrine\DBAL\DBALException]
  Unknown column type "double" requested. Any Doctrine type that you use has to be registered with \Doctrine\DBAL\Types\Type::addType(). You can get a list of all the kn
  own types with \Doctrine\DBAL\Types\Type::getTypesMap(). If this error occurs during database introspection then you might have forgot to register all database types f
  or a Doctrine Type. Use AbstractPlatform#registerDoctrineTypeMapping() or have your custom types implement Type#getMappedDatabaseTypes(). If the type name is empty you
   might have a problem with the cache or forgot some mapping information.

上面问题出现的原因,是migration 提供的数据类型和doctrine/dbal提供的数据类型存在着差异。即在migration中提供了double类型的接口,而doctrine/dbal中只存在float。

解决办法是,参考doctrine/dbal文档提供的数据类型来进行更改:doctrine/dbal 类型


Laravel

登陆发表评论