Symfony 5 + Doctrine 2 迁移至Oracle 19c时遭遇未知数据库类型错误求助
Hey Michael, I’ve faced this exact error when working with Oracle 19c and Doctrine DBAL 2.x, so let me walk you through the troubleshooting steps that helped me resolve it. Even if your entities don’t use interval types, Doctrine’s schema introspection might be picking up these types from unexpected places in your Oracle database.
1. 调整Schema Filter规则
Your current schema_filter excludes specific table prefixes, but Oracle has a lot of system tables, views, and metadata objects that Doctrine might still scan. Try tightening the filter to only include your application’s tables instead of excluding unwanted ones. For example, if your tables all start with a specific prefix like app_, update the filter:
schema_filter: ~^app_~
If you can’t use an include pattern, expand the exclude list to cover system objects that might contain interval types (like ALL_* or USER_* views, though be careful not to exclude your own tables).
2. 为Interval类型添加自定义映射
Doctrine’s OraclePlatform might not recognize the specific interval syntax interval day(3) to second(2) out of the box. You can explicitly map this type to a Doctrine-supported type in your doctrine.yaml:
oracle: # ... other configs mapping_types: enum: string interval day(3) to second(2): string
Alternatively, use a broader mapping for all interval variants:
mapping_types: enum: string interval: string
This tells Doctrine to treat any interval type it encounters as a string, which skips the unsupported type error.
3. 明确指定Oracle Server版本
Your server_version is set to ~ (null), which makes Doctrine guess the database version. For Oracle 19c, explicitly set this to ensure Doctrine uses the correct platform implementation:
server_version: '19'
Older DBAL versions might not properly infer Oracle 19c’s capabilities without this setting, leading to type detection issues.
4. 检查数据库中的视图/自定义对象
Even if your entities don’t use interval types, any database views, materialized views, or stored procedures that reference interval types could trigger this error during schema introspection. Use Oracle’s SQL commands to check for such objects:
SELECT table_name, column_name, data_type FROM user_tab_columns WHERE data_type LIKE '%INTERVAL%';
If you find any, add their names to your schema_filter exclusion list to prevent Doctrine from scanning them.
5. 考虑升级Doctrine DBAL
DBAL 2.12.1 is a bit old (released in 2021), and later versions in the 2.x branch have improved Oracle 19c support. Check if upgrading to DBAL 2.13.x or 2.14.x is compatible with your Symfony 5 and Doctrine ORM 2.8.2 setup. You can update via Composer:
composer require doctrine/dbal:^2.13
Just make sure to test this in a staging environment first to avoid breaking changes.
内容的提问来源于stack exchange,提问作者Michael Schrading

