Command "doctrine:generate:entities" is not defined - symfony

I encounter a problem with Symfony and the Doctrine entities generator.
When I call php app/console doctrine:generate:entities MyCompany, command fail and throw this exception :
[InvalidArgumentException]
Command "doctrine:generate:entities" is not defined.
Did you mean one of these?
doctrine:generate:entity
doctrine:generate:form
doctrine:generate:crud
I saw in many post people who had similar problems. But theirs related the doctrine:generate:entity command. They had forgotten :
"sensio/generator-bundle": "2.3.*" // in composer.json
and
new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle(); // in AppKernel
In my case everything is OK with composer.json and AppKernel. For example, these commands work : doctrine:generate:entity, doctrine:generate:form and doctrine:generate:crud
But doctrine:generate:entities doesn't :/
Here is an extract from my php app/console list command :
[...]
doctrine
doctrine:cache:clear-metadata Clears all metadata cache for an entity manager
doctrine:cache:clear-query Clears all query cache for an entity manager
doctrine:cache:clear-result Clears result cache for an entity manager
doctrine:database:create Creates the configured databases
doctrine:database:drop Drops the configured databases
doctrine:ensure-production-settings Verify that Doctrine is properly configured for a production environment.
doctrine:generate:crud Generates a CRUD based on a Doctrine entity
doctrine:generate:entity Generates a new Doctrine entity inside a bundle
doctrine:generate:form Generates a form type class based on a Doctrine entity
doctrine:mapping:convert Convert mapping information between supported formats.
doctrine:mapping:import Imports mapping information from an existing database
doctrine:mapping:info Shows basic information about all mapped entities
doctrine:query:dql Executes arbitrary DQL directly from the command line.
doctrine:query:sql Executes arbitrary SQL directly from the command line.
doctrine:schema:create Executes (or dumps) the SQL needed to generate the database schema
doctrine:schema:drop Executes (or dumps) the SQL needed to drop the current database schema
doctrine:schema:update Executes (or dumps) the SQL needed to update the database schema to match the current mapping metadata
doctrine:schema:validate Validates the doctrine mapping files
[...]
generate
generate:bundle Generates a bundle
generate:controller Generates a controller
generate:doctrine:crud Generates a CRUD based on a Doctrine entity
generate:doctrine:entity Generates a new Doctrine entity inside a bundle
generate:doctrine:form Generates a form type class based on a Doctrine entity
[...]
And here some informations about my project vendors versions
symfony/symfony v2.3.24 The Symfony PHP framework
sensio/framework-extra-bundle v2.3.4 This bundle provides a way to configure your controllers with annotations
sensio/generator-bundle v2.3.5 This bundle generates code for you
doctrine/annotations v1.2.3 Docblock Annotations Parser
doctrine/cache v1.4.0 Caching library offering an object-oriented API for many cache backends
doctrine/collections v1.2 Collections Abstraction library
doctrine/common v2.4.2 Common Library for Doctrine projects
doctrine/dbal v2.4.4 Database Abstraction Layer
doctrine/doctrine-bundle v1.2.0 Symfony DoctrineBundle
doctrine/inflector v1.0.1 Common String Manipulations with regard to casing and singular/plural rules.
doctrine/lexer v1.0.1 Base library for a lexer that can be used in Top-Down, Recursive Descent Parsers.
doctrine/orm v2.4.7 Object-Relational-Mapper for PHP
Thank's for your help ! :)

Ok I found the solution to my problem so I post the answer here hopping that it might help somebody one day :)
The command doctrine:generate:entities is provided by the file DoctrineBundle/Command/GenerateEntitiesDoctrineCommand.php (https://github.com/doctrine/DoctrineBundle/blob/v1.2.0/Command/GenerateEntitiesDoctrineCommand.php). And this file was mysteriously disappeared ! It's weird...
To fix that I deleted doctrine/doctrine-bundle folder from vendors and run a composer update
Voilà :)

Related

Doctrine message "Feature was deprecated" after doctrine:schema:update command

I get this message in red box when I try to run php bin/console doctrine:schema:validate or php bin/console doctrine:schema:update -f:
"Feature was deprecated in doctrine/dbal 2.x and is not supported by installed doctrine/dbal:3.x, please see the doctrine/deprecations logs for new alternative approaches."
Symfony 5.3.12
Doctrine 2.7.1-DEV
Any ideas where and what I should search for this message? Thank you!
I guess these commands were deprecated because of the idea that all schema changes should go through migrations and so - be represented in code and be reviewed before execution. The old approach could not guarantee that data wouldn't be lost (as many of schema:update manipulations allowed removing column and creating a new one to rename it without migrating the values).
The better approach to update DB schema is using maker bundle and migration mechanism.
composer require symfony/maker-bundle --dev
composer require doctrine/doctrine-migrations-bundle
bin/cosnole make:migration will generate migration based on differences of schema in code (annotations, xml or yml) and a current DB schema.
bin/console doctrine:migrations:migrate will execute migration.
As a result you will get same thing as by running bin/console doctrine:schema:update -f.

Symfony 4 doctrine use cache even in development environment

I am in development mode (APP_ENV=dev in .env), and everytime I change entities and run the 'make:migration' command, it returns me that there is no database changes.
After I run the 'cache:clear' command, it takes the changes into account and makes the migration file.
It's quite annoying. Do you have any idea from where it could come ?
I use the 'symfony server:start' to run the dev server, maybe it comes from here ?
If this is an annotation cache from a bundle that causing the issue, simple cache:clear might not help. Did you try do run doctrine:migration:diff?
You can also try to use --flush with your commands:
php bin/console doctrine:cache:clear-query --env=dev --flush
php bin/console doctrine:cache:clear-result --env=dev --flush
php bin/console doctrine:cache:clear-metadata --env=dev --flush
Update after comments:
What I meant, the complete way you use to deploy the entity changes.
As per Symfony 4, an entity update flow might look like below:
Update your entity class - your php/annotation changes
Clearing ALL Metadata cache entries
php bin/console doctrine:cache:clear-metadata
Generate a migration by comparing your current database to your mapping information.
php bin/console doctrine:migrations:diff
View the status of a set of migrations
php bin/console doctrine:migrations:status
Deploy migration
php bin/console doctrine:migrations:migrate --all-or-nothing
using option --all-or-nothing multiple migrations ran at the same time will be wrapped in a single transaction.
If one migration fails, all migrations will be rolled back.
More about migrations from official source: https://symfony.com/doc/master/bundles/DoctrineMigrationsBundle/index.html
Similar problem explained also here: Update an entity in Symfony 4?
Hope this will help and fix your issue.

impossible to generate bundle

i'm new to the symfony framework and i'm trying to generate my first bundle ,
i use this command php bin/console generate:bundle but it's not working.
The error message :
There are no commands defined in the "generate" namespace.
You may be looking for a command provided by the SensioGeneratorBundle which is currently not installed.
Try running composer require sensio/generator-bundle.
https://imgur.com/csryfHZ
I've tried to install composer repositories with the command composer require sensio/generator-bundle and nothing has changed
In symfony 4, this bundle is deprecated, you must use the maker-bundle, unfortunately there is no bundle generator available. So you'll need to code your bundle from scratch with the official documentation: https://symfony.com/doc/current/bundles/best_practices.html
By the way, bundle are deprecated and are now only use to share packaged code between projects.
More informations at: https://symfony.com/doc/current/bundles.html
We're not making bundle in Symfony 4.
While it was "good practice" withg Symfony 2, since the new skeleton, it's not the case anymore.
Your default bundle is now App, all your code goes in src/, and all your view (twig files) goes in template/

composer install does not update psr4 autoloader

I am using composer with a symfony project which require sonata-project/sonata-doctrine-orm-bundle and its dependencies (naturally with many other dependencies).
When I update symfony 2.3.6 to 2.5.5 and my vendors turn by turn, it updates sonata doctrine orm bundle which was written using PSR-0 autoloader and now uses PSR-4.
When composer finished to update all vendors and the symfony console command cache:clear run I get an error like class Sonata\DoctrineORMAdminBundle\SonataDoctrineORMAdminBundle can not be found.
When I look around to check what could be wrong, I discovered that the file vendor/composer/autoload_psr4.php is not updated with the path. The composer.json of sonata doctrine orm admin bundle is compliant with the paths I found in my vendor directory.
Does anyone have had the same or similar issue ? I can't find anything interesting about this...
Try to update composer, this was the issue I had when having problems with PSR-4 autoloading

Can't manage to put data into my database

I am using Symfony 2.0 beta3 and I am facing a rather strange problem. I have
set up the ORM with a sqlite database following the instructions of
the website but when I type:
php app/console doctrine:database:create
then
php app/console doctrine:schema:create
and finally
php app/console doctrine:schema:update --force
I don't get any error (for example last command outputs "Database
schema updated successfully") but nothing is actually inserted into
the database. The table aren't even created. The database file is
generated after the first command but remains empty.
Since I have configured FOS_UserBundle I should have for example a
table fos_user…
When I type
php app/console doctrine:schema:update --dump-sql
It shows that three SQL requests are pending… If I execute these three requests using
SQLiteManager, it works (so the fos_user table is created)
but when I want to create a user using:
php app/console fos:user:create
I get a "SQLSTATE[HY000]: General error: 1 no such table: fos_user " error.
Why am I not given some error message when I run the first three
commands? Am I missing something?
I face the same behaviour using pdo_pgsql driver, except that the SQL
generated by the dump is not ANSI compliant so it can't be executed
for postgresql (use of datetime and autoincrement instead of timestamp
and serial)….
Any help would be much appreciated
I found this solution on the Symfony forums.
It would seem the helpers aren't creating two things that you need for the sqlite implementation to work correctly.
Firstly, in the parameters.ini for the project (tweak to suit):
database_path=%kernel.root_dir%/config/MyDatabase.db
Secondly, in the config.yml file in the doctrine.dbal section, add the following:
path: %database_path%
Then run:
php app/console doctrine:database:create
and it should generate the database for you in the app/config folder.
You will need to run:
php app/console doctrine:schema:create
to create the schema. Re-run the code that didn't work and it should work fine.
The FOSUserBundle is developed in sync to the symfony master.
Be sure to updated both, symfony and the FOSUserBundle.
Drop the schema (php app/console doctrine:schema:drop --force)
Manually check the db whether the schema is dropped. Otherwise do it per hand.
Clear the cache and ensure that it is writeable.
Run php app/console doctrine:schema:update --force again.

Resources