Doctrine ORM Manager named "" does not exist - syntax error - php

I think all parameters are set properly but when I run command of
php bin/console doctrine:schema:update --force --em=archive
it throws an error:
Doctrine ORM Manager named "archive" does not exist.
So I think I might have a syntax problem that I cannot find.
My code:
doctrine:
dbal:
default_connection: default
connections:
default:
driver: pdo_mysql
host: '%database_host%'
port: '%database_port%'
dbname: '%database_name%'
user: '%database_user%'
password: '%database_password%'
charset: UTF8
archive:
driver: pdo_mysql
host: '%database2_host%'
port: '%database2_port%'
dbname: '%database2_name%'
user: '%database2_user%'
password: '%database2_password%'
charset: UTF8
orm:
auto_generate_proxy_classes: '%kernel.debug%'
naming_strategy: doctrine.orm.naming_strategy.underscore
mappings:
Default:
mapping: true
type: annotation
dir: '%kernel.root_dir%/../src/App/Base/Entity'
alias: 'Default'
prefix: 'Default\Base\Entity'
is_bundle: false
Archive:
mapping: true
type: annotation
dir: '%kernel.root_dir%/../src/App/Base/Entity/Archive'
alias: 'Archive'
prefix: 'App\Base\Entity\Archive'
is_bundle: false
Also I set parameters.yml correctly, too.

Related

Create Symfony Entity with multiple Entity-Managers

I have a Symfony project with the doctrine.yaml file below. So I have two entity managers (default and user) that connect my two databases. But how do I create a new entity now?
# config/packages/doctrine.yaml
doctrine:
dbal:
default_connection: default
connections:
default:
# configure these for your database server
url: '%env(resolve:DATABASE_URL)%'
driver: 'pdo_mysql'
server_version: '8'
charset: utf8mb4
user:
# configure these for your database server
url: '%env(resolve:DATABASE2_URL)%'
driver: 'pdo_mysql'
server_version: '8'
charset: utf8mb4
orm:
default_entity_manager: default
entity_managers:
default:
connection: default
mappings:
Admin:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity/Admin'
prefix: 'App\Entity\Admin'
alias: Admin
user:
connection: user
mappings:
User:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity/User'
prefix: 'App\Entity\User'
alias: User
With make:entity there is now an error, because this command only works with one entity manager (please correct me if it works somehow).

error The attribute "name" must be set for path "doctrine.orm.entity_managers.db2.mappings" with multiple databases

I have a project that uses two databases. The Doctrine section of Config.yml bundle is setup as follows.
doctrine:
dbal:
default_connection: db1
connections:
db1:
driver: pdo_mysql
host: "%database_host2%"
port: "%database_port2%"
dbname: "%database_name2%"
user: "%database_user2%"
password: "%database_password2%"
charset: UTF8
db2:
driver: pdo_mysql
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
orm:
default_entity_manager: em1
entity_managers:
em1:
connection: db1
mapping:
FirstBundle: ~
em2:
connection: db2
mappings:
SecondBundle: ~
All the parameters are setup in the parameters.yml file correctly.
whenever I run any $ php bin/console commands I get the following error
[Symfony\Component\Config\Definition\Exception\InvalidConfigurationException]
The attribute "name" must be set for path "doctrine.orm.entity_managers.em2.mappings".
Are there any settings that I'm missing?
I notice your em1 section is set to mapping instead of mappings. Also, in my working config, I set default_entity_manager to the connection value. So maybe try making these changes:
orm:
default_entity_manager: db1
entity_managers:
em1:
connection: db1
mappings:
FirstBundle: ~
em2:
connection: db2
mappings:
SecondBundle: ~
That may not be the problem, but try it.

Symfony2 Doctrine ORM Manager named “db2” does not exist

I create YML entity, generate entity and config multiple connections
config.yml
# Doctrine Configuration
doctrine:
dbal:
default_connection: db1
connections:
db1:
driver: '%database_driver%'
host: '%database_host%'
port: '%database_port%'
dbname: '%database_name%'
user: '%database_user%'
password: '%database_password%'
charset: UTF8
db2:
driver: '%database_driver2%'
host: '%database_host2%'
port: '%database_port2%'
dbname: '%database_name2%'
user: '%database_user2%'
password: '%database_password2%'
charset: UTF8
orm:
auto_generate_proxy_classes: "%kernel.debug%"
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
my orm.yml
TestBundle\Entity\Test:
type: entity
table: Test
id:
id:
type: integer
nullable: false
options:
unsigned: true
id: true
fields:
name:
type: string
nullable: false
length: 255
options:
fixed: false
lifecycleCallbacks: { }
after clean cache and generate entities, I try to run this code (in command controller)
<?php
...
protected function execute(InputInterface $input, OutputInterface $output)
{
$doctrine = $this->getContainer()->get('doctrine')->getManager('db2');
//both methods cant work :( db2_entity_manager not found
$doctrine = $this->getContainer()->get('doctrine.orm.db2_entity_manager');
$test = $doctrine->getRepository('DionisDataBaseBundle:Test');
}
And I have error:
[InvalidArgumentException]
Doctrine ORM Manager named "db2" does not exist.
change config.yml to
orm:
auto_generate_proxy_classes: "%kernel.debug%"
default_entity_manager: db1
entity_managers:
db1:
connection: db1
mappings:
DionisDataBaseBundle: ~
db2:
connection: db2
mappings:
DionisDataBaseBundle: ~
db3:
connection: db2
mappings:
DionisDataBaseBundle: ~
you just declared connections but no entity manager, from one of my projects :
doctrine:
dbal:
default_connection: default
connections:
default:
host: "%database_host%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
driver_class: Realestate\MssqlBundle\Driver\PDODblib\Driver
mapping_types:
enum: string
string: string
# schema_filter: ~^(sf_fos_user)~
prod:
host: *****
dbname: ****
user: "%database_user%"
password: "%database_password%"
driver_class: Realestate\MssqlBundle\Driver\PDODblib\Driver
mapping_types:
enum: string
string: string
# schema_filter: ~^(sf_fos_user)~
orm:
default_entity_manager: default
entity_managers:
default:
connection: default
mappings:
AppBundle: ~
Bundle2: ~
db2:
connection: prod
mappings:
otherBundle: ~
auto_generate_proxy_classes: "%kernel.debug%"

Symfony2 : Error with entitymanager configuration

Error : InvalidConfigurationException: Unrecognized options "auto_mapping" under "doctrine.orm"
This is my config.yml file code
# Doctrine Configuration
doctrine:
dbal:
default_connection: default
connections:
default:
driver: "%database_driver%"
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
symfonydb:
driver: pdo_mysql
host: localhost
port: null
dbname: symfony
user: root
password: null
charset: UTF8
# if using pdo_sqlite as your database driver, add the path in parameters.yml
# e.g. database_path: "%kernel.root_dir%/data/data.db3"
# path: "%database_path%"
orm:
auto_generate_proxy_classes: "%kernel.debug%"
auto_mapping: true
default_entity_manager: default <<<<<<<<<<
entity_managers:
default:
connection: default
mappings:
AcmeDemoBundle: ~
AcmeUserBundle: ~
symfonydb:
connection: symfonydb
mappings:
FooNewsBundle: ~ <<<<<<<<<
If I remove code which is after auto_mapping: true, then it works fine and not throw any error.
So what is the problem?
Thnaks.
Have a look at this GitHub issue: Problem with installation?
The auto_mapping entry goes under the entity_managers.default node, not on the root of the orm node.

Generate entities using xml mappings using command doctrine:genereate:entities to a different location other than the default location

I am using symfony2 with doctrine.
Here is my parameters.yml
parameters:
database_driver: pdo_mysql
database_host: localhost
database_port: ~
database_name: somedb
database_user: root
database_password: ~
Here is my config.yml
# Doctrine Configuration
doctrine:
dbal:
driver: %database_driver%
dbname: %database_name%
host: %database_host%
port: %database_port%
user: %database_user%
password: %database_password%
charset: UTF8
orm:
auto_generate_proxy_classes: %kernel.debug%
auto_mapping: false
mappings:
name:
type: xml
dir: %kernel.root_dir%/../src/bundlename/Resources/config/doctrine
prefix: bundlename\Model\Entity
is_bundle: false
Running doctrine:mapping:import generates the xml mappings files in the following directory
*bundlename\Resources\config\doctrine*
Running doctrine:generate:entities gives the following error:
Generating entities for bundle "bundlename"
[Doctrine\Common\Persistence\Mapping\MappingException]
Invalid mapping file 'bundlename.Model.Entity.some_entity
.orm.xml' for class 'bundlename\Model\Entity\some_entity'
.
Using auto_mapping: true correctly generates the entities at bundlename\Entity*
What I want to accomplish here is to instruct doctrine to generate entities at a different location other than the default location

Categories