簡體   English   中英

如何修復“請求的未知數據庫類型幾何,Doctrine\DBAL\Platforms\PostgreSQL100Platform 可能不支持它。”

[英]How to fix “Unknown database type geometry requested, Doctrine\DBAL\Platforms\PostgreSQL100Platform may not support it.”

我正在嘗試准備 Symfony 3.4.32 + PostgreSQL + PostGIS 環境。 我安裝了jsor/doctrine-postgis ,但是發生了以下錯誤。

請求的未知數據庫類型幾何,Doctrine\DBAL\Platforms\PostgreSQL100Platform 可能不支持它。

細節

我正在使用EC-CUBE 4.0.3,它是使用 Symfony 3.4.32 的開源軟件。

我准備了 mdillon/postgis docker 容器。 我啟用了 postgis 擴展,我可以使用 PostGIS。

我通過 composer 安裝了jsor/doctrine-postgis並設置了配置文件。

  1. 我將設置添加到 app/config/eccube/services.yaml 的底部。
 services:
     # (ommitted)
      Jsor\Doctrine\PostGIS\Event\ORMSchemaEventSubscriber:
         tags:
             - { name: doctrine.event_subscriber, connection: default }
  1. 我將三種類型(地理、幾何、柵格)添加到 app/config/eccube/packages/doctrine.yaml。
parameters:
     # Adds a fallback DATABASE_URL if the env var is not set.
     # This allows you to run cache:warmup even if your
     # environment variables are not available yet.
     # You should not need to change this value.
     env(DATABASE_URL): ''
     env(DATABASE_SERVER_VERSION): ~
 doctrine:
     dbal:
         driver: 'pdo_pgsql'
         server_version: "%env(DATABASE_SERVER_VERSION)%"
         charset: utf8

         # for mysql only
         default_table_options:
           collate: 'utf8_general_ci'

         # With Symfony 3.3, remove the `resolve:` prefix
         url: '%env(DATABASE_URL)%'

         # types
         types:
             datetime: 'Eccube\Doctrine\DBAL\Types\UTCDateTimeType'
             datetimetz: 'Eccube\Doctrine\DBAL\Types\UTCDateTimeTzType'
             geography:
                 class: 'Jsor\Doctrine\PostGIS\Types\GeographyType'
                 commented: false
             geometry:
                 class: 'Jsor\Doctrine\PostGIS\Types\GeometryType'
                 commented: false
             raster:
                 class: 'Jsor\Doctrine\PostGIS\Types\RasterType'
                 commented: false
     orm:
         auto_generate_proxy_classes: '%kernel.debug%'
         naming_strategy: doctrine.orm.naming_strategy.underscore
         auto_mapping: true
         dql:
             string_functions:
                 NORMALIZE: Eccube\Doctrine\ORM\Query\Normalize
             numeric_functions:
                 EXTRACT: Eccube\Doctrine\ORM\Query\Extract
         filters:
             option_nostock_hidden:
                 class: Eccube\Doctrine\Filter\NoStockHiddenFilter
                 enabled: false
             incomplete_order_status_hidden:
                 class: Eccube\Doctrine\Filter\OrderStatusFilter
                 enabled: false
  1. 我准備了實體,app/Customize/Entity/Geolocation.php。
<?php
 namespace Customize\Entity;
 use Doctrine\ORM\Mapping as ORM;

 /**
  * GeoLocation
  *
  * @ORM\Table(name="dtb_geolocation")
  * @ORM\InheritanceType("SINGLE_TABLE")
  * @ORM\DiscriminatorColumn(name="discriminator_type", type="string", length=255)
  * @ORM\HasLifecycleCallbacks()
  * @ORM\Entity(repositoryClass="Customize\Repository\GeoLocationRepository")
  */
 class GeoLocation extends \Eccube\Entity\AbstractEntity
 {
     /**
      * @ORM\Column(name="gid", type="integer", options={"unsigned":true})
      * @ORM\Id
      * @ORM\GeneratedValue(strategy="IDENTITY")
      */
     public $gid;

     // (ommitted)

     /**
      * @ORM\Column(name="geom", type="geometry", options={"geometry_type"="MULTIPOLYGON", "srid"=4612}, nullable=true)
      */
     public $geom;
 }    
  1. 然后我在 PostgreSQL 數據庫中創建了該表。

bin/console eccube:generate:proxies
bin/console doctrine:schema:update --dump-sql --force
  1. 它工作正常。 在 PostgreSQL 中創建並檢查了“dtb_geolocation”表。
 db=# \d dtb_geolocation ;
                                             Table "public.dtb_geolocation "
       Column       |            Type             | Collation | Nullable |                          Default
--------------------+-----------------------------+-----------+----------+-----------------------------------------------------------
 gid                | integer                     |           | not null | nextval('dtb_geolocation_pkey'::regclass)

// ommitted

 geom               | geometry(MultiPolygon,4612) |           |          | NULL::geometry
 discriminator_type | character varying(255)      |           | not null |
Indexes:
    "dtb_geolocation_pkey" PRIMARY KEY, btree (gid)

但是當我在瀏覽器上訪問時,就會發生錯誤。

請求的未知數據庫類型幾何,Doctrine\DBAL\Platforms\PostgreSQL100Platform 可能不支持它。

我通過bin/console cache:clear --no-warmup清除緩存,但沒有任何變化。

我犯了什么錯誤嗎?
Symfony 中不包含幾何類型嗎? 我怎樣才能檢查它?

您是否在 postgresql 數據庫中創建了 postgis 擴展?

創建擴展 postgis;

也許這是一個 EC-CUBE 4 問題。 我猜 doctrine.yaml 是在 Symfony 識別數據庫表之后加載的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM