We've set our configuration file for doctrine migrations as the following:
doctrine_migrations:
migrations_paths:
'App\Migrations': "%kernel.project_dir%/src/Migrations"
Our migrations command all work, for example, doctrine:migrations:migrate works, doctrine:migrations:list will list all the migrations in our /src/Migrations folder. However, we cannot execute the doctrine:migrations:execute <versionNumber> command because it will give an error that it cannot find the migration file: "Migration class "20220329211652" was not found?"
Does doctrine:migrations:execute not work for custom migration paths configuration? When placing these migrations back in the default folder, it works.
It worked by using a fully qualified class name like:
bin/console doctrine:migrations:execute "App\Migrations\Version20220329211652"
Related
I wanted to create an entity, basing on a database table. I followed these steps: Doctrine/Symfony entity generator and generating entity from one table , that is, in terminal:
php bin/console doctrine:mapping:import --force AppBundle yml --force --filter="Client"
php bin/console doctrine:mapping:convert annotation ./src/AppBundle/Entity --from-database --filter="Client"
php bin/console doctrine:generate:entities AppBundle:Client --no-backup
This created the entity "Client". But, it also created a client.orm.yml file in the src/AppBundle/Resources/config/doctrine directory. And this causes problems - that is, my application now crashes with an error message:
"No mapping file found named 'User.orm.yml' for class
'AppBundle\Entity\User'"
I think Symfony/Doctrine started using those yml files to map my php code to database schema. But why? I didn't want it. I just wanted Doctrine to create an entity.
p.s. When I remove this client.orm.yml file, everything works fine. But I don't understand what is happening, and how should I handle it properly.
You can delete these files after entity creation process. These files for metadata mapping.
You can read this
martinfowler.com/eaaCatalog/metadataMapping.html and martinfowler.com/eaaCatalog/dataMapper.html
Why doctrine does not delete ? Because, it is first step for convert process. Your first command creating those files after you command to doctrine and it is creating Entity files referenced with those files. :)
I am using symfony2 and doctrine and today using command
php app/console doctrine:schema:update --force
encountered the following error:
[Doctrine\Common\Persistence\Mapping\MappingException] Class
'AppBundle\Entity\Linkksiazkaokladka' does not exist
eventhough I had no Entity\Linkksiazkaokladka.php file.
I have also noticed that:
php app/console doctrine:generate:entities AppBundle
generates entities which are not available in /entity/ directory.
Make sure that your Resource/Config/Doctrine directory is clear.
It seems that Doctrine generates entities first of all based on data in this directory.
In my case clearing Resource/Config/Doctrine helped.
I'm new to symfony and doctrine, so please correct me if I'm wrong.
If I run the command
php app/console doctrine:generate:entity
Doctrine creates an Entity with the given class name and the fields with the given types. Also it creates the mapping file.
Now what I would like is a command which creates only the mapping file.
Something like:
php app/console doctrine:generate:mapping
where doctrine creates only the mapping file on the class I wrote. Is that possible, how can I achieve that?
I don't understand fully what you need to do, in any case mapping files I guess could be generated only if read from an existent database or with a conversion of the mappings:
(in symfony) $ php app/console doctrine:mapping:convert
If you would like to use doctrine command it is in:
$ php vendor/doctrine/orm/bin/doctrine
But I never run this in a full stack symfony framework.
I've noticed this recently, from a clean install of Symfony2 and removed AcmeDemoBundle (from the AppKernel, routing_dev.yml etc.). I generate the bundle and noticed that the Target directory for the bundle has changed and every time I create a new bundle I have to manually put in the proper path to it. Seems to be a problem with the latest release of Symfony2.
Changed Target directory line during bundle creation:
Target directory [/var/www/html/Project/app/cache/dev/../src]:
The path that it use to point was:
Target directory [/var/www/html/Project/src]:
I am at a loss for what changed as I installed a clean build and did not alter any settings.
When I installed Symfony2 I used the following: (which is the same way I've used previously)
composer create-project symfony/framework-standard-edition Project #stable
php app/console generate:bundle (see last line)
Welcome to the Symfony2 bundle generator
Your application code must be written in bundles. This command helps
you generate them easily.
Each bundle is hosted under a namespace (like Acme/Bundle/BlogBundle).
The namespace should begin with a "vendor" name like your company name, your
project name, or your client name, followed by one or more optional category
sub-namespaces, and it should end with the bundle name itself
(which must have Bundle as a suffix).
See http://symfony.com/doc/current/cookbook/bundles/best_practices.html#index-1 for more
details on bundle naming conventions.
Use / instead of \ for the namespace delimiter to avoid any problem.
Bundle namespace: Foo/FooBundle
In your code, a bundle is often referenced by its name. It can be the
concatenation of all namespace parts but it's really up to you to come
up with a unique name (a good practice is to start with the vendor name).
Based on the namespace, we suggest FooFooBundle.
Bundle name [FooFooBundle]:
The bundle can be generated anywhere. The suggested default directory uses
the standard conventions.
Target directory [/var/www/html/Project/app/cache/dev/../src]:
Fixed by updating composer:
composer self-update
Then creating a new project.
So I have an existing database but I was unable to follow the steps outlined here: http://symfony.com/doc/current/cookbook/doctrine/reverse_engineering.html because some of my tables have foreign keys for primary keys.
My solution has been to create a copy of the database without foreign key constraints and generate the .yaml files from THAT first.
So now I have XXX.orm.yml files in ./src/My/MainBundle/Resources/config/doctrine/metadata/orm
Next I tried to turn these .yml files into Entity classes with annotations by using this command:
php app/console doctrine:mapping:import MyMainBundle annotation
However that ignores my .yml files. It either generates the generic classes from my database without foreign keys, or it throws an error if I use it on my real database. It never even looks at my .yml files.
So all I want to know, is how can I transform the *.orm.yml files to Entities?
I'm not 100% sure if this is all I had to do to fix it, but I think the solution was as simple as moving my .orm.yml files from
./src/My/MainBundle/Resources/config/doctrine/metadata/orm
to
./src/My/MainBundle/Resources/config/doctrine
and running
php app/console doctrine:mapping:import MyMainBundle annotation --path="./src"
Use convert after import to convert yaml to entity annotations :
php bin/console doctrine:mapping:convert annotation src
See --help for further informations.
To force override entity files use --force option.
To create accessors (getters and setters) use
php bin/console doctrine:generate:entities yourBundle
Don't forget to check if yml files don't override behavior of annotation changes...
Regards
--path isn't an option to the command doctrine:mapping:import
after:
php bin/console doctrine:mapping:import YourBundle yml
use:
php bin/console doctrine:generate:entities YourBundle