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.
Related
I used this documentation : https://symfony.com/doc/4.4/doctrine/multiple_entity_managers.html
So now I can create new databases named legacy and Project like this
doctrince.yaml:
doctrine:
dbal:
default_connection: legacy
connections:
legacy:
driver: pdo_mysql
host: "%env(database_host)%"
port: "%env(database_port)%"
dbname: "%env(database_name)%"
user: "%env(database_user)%"
password: "%env(database_password)%"
charset: UTF8
project:
driver: pdo_mysql
host: "%env(database_host_project)%"
port: "%env(database_port_project)%"
dbname: "%env(database_name_project)%"
user: "%env(database_user_project)%"
password: "%env(database_password_project)%"
charset: UTF8
orm:
default_entity_manager: legacy
entity_managers:
legacy:
connection: legacy
mappings:
Legacy:
is_bundle: false
type: annotation
dir: "%kernel.project_dir%/..."
prefix: '...'
alias: Legacy
project:
connection: project
auto_mapping: true
mappings:
Project:
is_bundle: false
type: annotation
dir: "%kernel.project_dir%/src/Entity"
prefix: 'App\Entity'
alias: Project
Now I have several Fixture classes all of them depend on each other and also some will create fixture for legacy and some will create for project.
Now my question is when I do:
php bin/console doctrine:fixtures:load --em=legacy
It runs the appfixtures of the project but not the of the bundle.
and then i get this error:
The class .. was not found in the chain configured namespaces ....
My question is now how can I load fixtures on multiple databases with multiple connections.
Thanks in advance.
You should read this doc : https://symfony.com/doc/current/doctrine/multiple_entity_managers.html
I think it may solve your problem as this is exactly what you trying to do.
If you have to create a fixture for legacy just use :
$entityManager = $this->getDoctrine()->getManager('legacy');`
else if it is for project use
$entityManager = $this->getDoctrine()->getManager('project');`
Also, if you change doctrine.dbal.default_connection, entityManager will run against the defined connection.
So you can try to create group of fixtures.
And then run fixtures for project :
Edit config for test environment
#config/packages/test/doctrine.yaml
doctrine:
dbal:
default_connection: 'project'
Then run fixture for 'project' group
> php bin/console doctrine:fixtures:load --group=project
Then do the same thing for 'legacy'
I have an existing entity in a Symfony3 project that I am trying to add an entity manager to. My doctrine.yml file looks like this
doctrine:
dbal:
default_connection: default
connections:
default:
driver: pdo_mysql
host: localhost
port: 3306
dbname: fullstackdb
user: root
password: root
charset: UTF8
lego:
driver: pdo_mysql
host: localhost
port: 3306
dbname: fullstackdb
user: root
password: root
charset: UTF8
orm:
default_entity_manager: default
entity_managers:
auto_mapping: true
default:
connection: default
mappings:
lego:
connection: lego
mappings:
AppBundle: ~
However anytime I try to access this entity manager through php bin/console doctrine:database:create --connection=lego
, it says the manager does not exist! I'm not sure if I'm missing a step - the only thing I've done to create the manager is to make the yml file.
It doesn't show up when I run bin/console debug:container.
Grateful for any help!
1) You are using the same schema name (database name) on the same host in two different entity managers without schema_filters. This means that when you do an update to one of the entity managers it will attempt to delete the data of the other entity manager.
2) You are asking about a entity manager but in the command you are passing a connection.
3) Run php bin/console debug:container | grep doctrine
This will give you all the doctrine services. Update your question accordingly.
4) Provide the exact command and exact error you get so we can track it down to the origin
5) For a more information run the command in verbose mode adding -v at the end
6) Are you importing your doctrine.yml in your config.yml ?
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"
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'