When running doctrine:mapping:import i get an error:
Unknown database type enum requested, Doctrine\DBAL\Platforms\MySqlPlatform may not support it.
It seems I need to set use_native_enum to true some how. However, all documentation and blog posts are refering to Symfony < 1.4. Is there any what would be the solution in Symfony 2?
For Symfony 2 projects, add this to the doctrine dbal configuration in app/config.yml:
doctrine:
dbal:
mapping_types:
enum: string
My full doctrine config looks like this:
# Doctrine Configuration
doctrine:
dbal:
driver: %database_driver%
host: %database_host%
port: %database_port%
dbname: %database_name%
user: %database_user%
password: %database_password%
charset: UTF8
mapping_types:
enum: string
set: string
varbinary: string
tinyblob: text
orm:
auto_generate_proxy_classes: %kernel.debug%
auto_mapping: true
Code adapted from here
Then run:
app/console doctrine:schema:update --force --dump-sql --ansi
Considering the Doctrine cookbook only provides partial answers as to how to make enums interpret as strings, the following should work regardless of how Doctrine is configured.
The error points you at the name of the file: Doctrine\DBAL\Platforms\MySqlPlatform.php - in there, you'll find that the default list is embedded in the function initializeDoctrineTypeMappings as follows:
$this->doctrineTypeMapping = array(
'tinyint' => 'boolean',
'smallint' => 'smallint',
'mediumint' => 'integer',
'int' => 'integer',
(...)
Adding simple enum support for all doctrine users, regardless of the rest of the setup, is simply achieved by extending the list with:
'enum' => 'string'
Related
I have Entity(s) and EntityHtml(s) entities which has one-to-one relashionship (Entity stores metadata and EntityHtml acts like a cache, storing ready HTML chunks for rendering).
I have defined a relationship in Entity class:
/**
* #ORM\OneToOne(targetEntity="EntityHtml")
* #ORM\JoinColumn(name="entityId", referencedColumnName="entityId")
*/
private $entityHtml;
but it isn't working. Also I have a kind of feeling, that annotations don't work at all, because changing them has no effect upon workability of the application.
On the other hand, messing with .orm.xml(s) reflects in how application works.
Can I tell Symfony to update ORM XMLs based on changes to annotations?
Should I duplicate relation meta to XML?
Does Symfony use info at both XML and annotations or does it choose one source?
config.yml is default one:
# Doctrine Configuration
doctrine:
dbal:
driver: pdo_mysql
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
# if using pdo_sqlite as your database driver:
# 1. add the path in parameters.yml
# e.g. database_path: "%kernel.root_dir%/data/data.db3"
# 2. Uncomment database_path in parameters.yml.dist
# 3. Uncomment next line:
# path: "%database_path%"
orm:
auto_generate_proxy_classes: "%kernel.debug%"
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
Does it make any difference if you try this:
/**
* #ORM\OneToOne(targetEntity="EntityHtml")
* #ORM\JoinColumn(name="entity_Id", referencedColumnName="entityId")
*/
I'm thinking that "entityId" is the Id in EntityHtml, and you need to specify a different "name" value in JoinColumn. I think I ran into that problem.
Try it - I'm not sure if it will work.
Figured this one out. It's a configuration issue. In order to make annotations work (xml is default option), you have to explicitly configure it:
# Doctrine Configuration
doctrine:
...
orm:
...
mappings:
AppBundle:
type: annotation
Unfortunatelly that's not specified in tutorials.
I have a problems with Doctrine on Sf2.7, when I run a command such as "doctrine: schema: update" I get:
[Doctrine\Common\Persistence\Mapping\MappingException] File mapping drivers must have a valid directory path, however the given path 0 seems to be incorrect!
This worked well until I make a drop of a database to recreate it in "clean" after a lot changed entities ...
Here is an excerpt from my config.yml
# Doctrine Configuration
doctrine:
dbal:
default_connection: default
connections:
default:
driver: pdo_mysql
dbname: "%database_name%"
host: "%database_host%"
port: "%database_port%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
orm:
default_entity_manager: default
entity_managers:
default:
connection: default
auto_mapping: true
all entities begin with this type of annotations:
/**
* User
*
* #ORM\Entity
* #ORM\Table(name="usr_user")
* #ORM\Entity(repositoryClass="Acme\UserBundle\Repository\UserRepository")
*/
I searched our friend Google, OpenClassRooms and here of course but not found ... someone an idea ?
Got the same error when I imported my project to another pc. The solution worked for me is to try clearing configuration cache using php artisan command.
php artisan config:cache
then try to create or update doctrine schema.
For Symfony, you need to clear var/cache directory.
It solved problem for me.
NOTE: Its not a Duplicate issue cause I have tried everything I get on google but nothing have helped us.
I am trying to import Tables using Doctrine Reverse Engineering tool, but I m getting this message:
Database does not have any mapping information.
My Connection Details in Config.yml
doctrine:
dbal:
default_connection: default
connections:
default:
driver: pdo_mysql
host: localhost
port: null
dbname: pixel_ashish
user: root
password: abc123
charset: UTF8
schema_filter: ~^(?!some_table1|some_table2)~
orm:
default_entity_manager: default
auto_generate_proxy_classes: true
proxy_dir: "%kernel.cache_dir%/doctrine/orm/Proxies"
proxy_namespace: Proxies
resolve_target_entities: []
What I have tried So Far:
Running php app/console doctrine:mapping:import --force AcmeBlogBundle xml
gives same error
Tried to convert mapping also which does not make any sense cause mappings are not there but still tried didn't worked out.
Created a new project and tried above given configuration didn't worked.
Now I am out of ideas please help me to solve this.
You need to create some mapping information in your config.
You can do it by passing auto_mapping: true under orm section:
doctrine:
orm:
auto_mapping: true
or by manually defining it under orm section:
doctrine:
orm:
default_entity_manager: default
entity_managers:
default:
connection: default
mappings:
YourBundleName:
type: "xml"
dir: "Entity"
prefix: "Your\BundleName\Entity"
So I want to generate entities for specific tables in a database that has a huge amount of tables.
Here is the command I'm trying:
php app/console doctrine:mapping:convert yml ./src/MyNamespace/Bundle/MyNamespaceBundle/Resources/config/doctrine/metadata/orm --from-database --em=my_manager --filter=TblReports --verbose
Here is the error:
[Doctrine\DBAL\DBALException]
Unknown database type unknown requested, Doctrine\DBAL\Platforms\PostgreSqlPlatform may not support it.
Now I can run this command on a smaller database with only a few tables and it works fine, so it has to be the database.
Yes I want to filter this one table:
--filter=TblReports
If I remove the filter it generates entities for the entire database, which is what I don't want.
I'm running PostgreSQL 8.4 and 9.1 if that matters.
Anyone else have or know how to fix this issue?
Unknown database type unknown requested
Doctrine Docs
http://docs.doctrine-project.org/projects/doctrine-orm/en/2.1/reference/tools.html#reverse-engineering
Releated:
Generating a single Entity from existing database using symfony2 and doctrine
UPDATE: Adding my_manager ( config.yml )
# Doctrine Configuration
doctrine:
dbal:
default_connection: my_database
connections:
my_database:
driver: pdo_pgsql
port: 5432
dbname: tbl_reports
user: foo_user
password: foo_pass
charset: UTF8
mapping_types:
bit: string
orm:
auto_generate_proxy_classes: "%kernel.debug%"
default_entity_manager: my_manager
entity_managers:
my_manager:
connection: my_database
mappings:
MyNamespaceBundle:
mapping: true
dir: Entity/Reports
in config_dev.yml ( I use the dev and prod yml files to control the host(s) I can connect to )
# Doctrine Configuration
doctrine:
dbal:
connections:
my_database:
host: 172.0.0.1
I agree with Ziumin that it's likely an issue with the data type in your Postgres database. Possibly an Enum or similar.
What I would do is try to convert the tables one by one until you narrow it down to the problem table, and then look at the data types and it should be fairly obvious.
How can I add my custom driver without modifying DriverManager.php in the Doctrine2 core?
I have created a DBAL Driver for pdo_dblib and placed it inside a Symfony2 bundle. This works fine, however I must add my driver to a list of hard-coded drivers in DriverManager.php, otherwise I get the following exception:
Exception
[Doctrine\DBAL\DBALException]
The given 'driver' pdo_dblib is unknown, Doctrine currently supports only the following drivers: pdo_mysql, pdo_sqlite, pdo_pgsql, pdo_oci, oci8, ibm_db2, pdo_ibm, pdo_sqlsrv
Unless I modify DriverManager.php
final class DriverManager
{
private static $_driverMap = array(
'pdo_dblib' => 'Doctrine\DBAL\Driver\PDODblib\Driver', // Added this line
);
}
Here's my config.yml:
# Doctrine Configuration
doctrine:
dbal:
driver: pdo_dblib
driver_class: PDODblibBundle\Doctrine\DBAL\Driver\PDODblib\Driver
You actually can, just leave the driver configuration option completlely out.
All you need to define is the driver_class option. The driver is only used to do an internal lookup for the default driver classes, as long as you provide the class only, it will not fail doing the lookup.
Btw: There is no way (in a complete default setup) to define this in the parameters.ini, you have to change it directly inside the config.yml
Btw: due to another defect (driver falling back to mysql in on specific area), you may not set the charset in the configuration, as it will register an MySql event handler for setting the charset than.
So my final doctrine config based on my mssql_* based implementation looks like the following and works without problems:
# Doctrine Configuration
doctrine:
dbal:
#driver: %database_driver%
driver_class: Doctrine\DBAL\Driver\MsSql\Driver
host: %database_host%
port: %database_port%
dbname: %database_name%
user: %database_user%
password: %database_password%
#charset: UTF8
orm:
auto_generate_proxy_classes: %kernel.debug%
auto_mapping: true
You can use the option driverClass:
$connectionParams = array(
'driverClass' => 'YOUR_CUSTOM_CLASS_DB',
);
$entityManager = \Doctrine\ORM\EntityManager::create($connectionParams, $config);