Reputation: 404
New to Symfony... Trying to create Entities from an existing DB. I am attempting to following the instructions at http://symfony.com/doc/current/cookbook/doctrine/reverse_engineering.html
Long story short it seems that I simply need 3 commands:
$ php bin/console doctrine:mapping:import --force AppBundle xml
$ php bin/console doctrine:mapping:convert annotation ./src
$ php bin/console doctrine:generate:entities AppBundle
Note: I Modified the name of the bundle from AcmeBlogBundle to AppBundle because I am just using the default bundle. I also am using Symfony 3, everything I look up online seems to reference symfony2
Anyway, first command seems to run fine. I get orm.xml files generated in my ./src/AppBundle/Resources/config/doctrine/ path Commands 2 and 3 seem to be where my troubles begin.
Command 2 results in
No Metadata Classes to process
Command 3 results in (obviously command 2 didnt work correctly but tried anyway)
[RuntimeException] Bundle "AppBundle" does not contain any mapped entities.
I'm at a loss here.
Contents of config.yml are:
imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: services.yml }
http://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:
locale: en
framework:
#esi: ~
#translator: { fallbacks: ["%locale%"] }
secret: "%secret%"
router:
resource: "%kernel.root_dir%/config/routing.yml"
strict_requirements: ~
form: ~
csrf_protection: ~
validation: { enable_annotations: true }
#serializer: { enable_annotations: true }
templating:
engines: ['twig']
#assets_version: SomeVersionScheme
default_locale: "%locale%"
trusted_hosts: ~
trusted_proxies: ~
session:
# handler_id set to null will use default session handler from php.ini
handler_id: ~
save_path: "%kernel.root_dir%/../var/sessions/%kernel.environment%"
fragments: ~
http_method_override: true
assets: ~
twig:
debug: "%kernel.debug%"
strict_variables: "%kernel.debug%"
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
swiftmailer:
transport: "%mailer_transport%"
host: "%mailer_host%"
username: "%mailer_user%"
password: "%mailer_password%"
spool: { type: memory }
I did end up getting past this by adding i think the "--from database" flag in one of the commands above. I think the second command. I'm pretty sure youre correct that my config is not expecting the xml files so thats why it cant find them.
Upvotes: 2
Views: 2972
Reputation: 101
you can run the following command straightaway after configuring your parameters.yml.
php bin/console doctrine:mapping:import --force AppBundle annotation
then you can run this command to generate entities
php bin/console doctrine:generate:entities AppBundle
It's also important to try your database connection before running any of those commands. Try to fetch values with
php bin/console doctrine:query:sql "SELECT * FROM your_table_name"
Upvotes: 2