I currently got orm set up on my silex application. Everything seems to work as expected except for when I run the command to generate the entities from my database (reverse-engineering).
../../../vendor/bin/doctrine orm:convert-mapping --namespace="Random\MyApp\Model\Random\Entities" --force --from-database annotation ./../random/entities
This command will create all of my entities perfectly but they will be under the folder structure
./../random/entities/Random/MyApp/Model/Random/Entities/(files here)
which is wrong since I am expecting to have
./../random/entities/(files here)
A namespace is actually the path under your entities are grouped. So it's perfectly logic that doctrine generates files under this namespace.
If you want a file structure like it just do :
../../../vendor/bin/doctrine orm:convert-mapping --namespace="random/entities" --force --from-database annotation ./
But this is definitely not conform with the PSR-0
Related
After creating an Entity and Repository from an existing pre-doctrine database, I am unable to make an initial migration. It gave me this error [ERROR] The version "latest" couldn't be reached, there are no registered migrations. Any idea how to do an initial migration without starting fresh? And for some reason, the migration folder exists outside the src folder, why is it so? In a previous project, the migration folder exists inside the src folder.
Any insight would be appreciated. Thank you for reading.
EDIT: doctrine_migrations.yaml:
doctrine_migrations:
migrations_paths:
# namespace is arbitrary but should be different from App\Migrations
# as migrations classes should NOT be autoloaded
'DoctrineMigrations': '%kernel.project_dir%/migrations'
The commands I used to generate the Entity and its Repository is as follows:
php bin/console doctrine:mapping:import "App\Entity" annotation --path=src/Entity
modified the #ORM\Entity => #ORM\Entity(repositoryClass="App\Repository\UserRepository") in the entity .php
php bin/console make:entity --regenerate
Then when I run bin/console doctrine:migrations:migrate, the error pops up.
Work for me
doctrine_migrations:
migrations_paths:
'App\Migrations': '%kernel.project_dir%/src/Migrations'
and use for migration classes
namespace App\Migrations;
THis is my migrations config.You can test it :
doctrine_migrations:
dir_name: '%kernel.project_dir%/src/Migrations'
# namespace is arbitrary but should be different from App\Migrations
# as migrations classes should NOT be autoloaded
namespace: DoctrineMigrations
For migration commande i use : php bin/console d:m:diff and after this you can use the migration number with this commande :
php bin/console d:m:e --up the_migration_number
I tried most of the methods but it seems that it is possible to generate the migration. However, changes to the entity will not be detected by doctrine.
For example, if I change the field of name to username, php bin/console doctrine:migration:diff does not detect the changes.
What I found worked was exporting the database as .sql, creating the entity the normal way, and manually typing in the fields. Delete the generated table in phpmyadmin, and importing the data back in. Only then would it be working as I want it to be.
Im using symfony framework with Doctrine as ORM.
When i run this command:
php bin/console doctrine:mapping:convert annotation ./src --env=local --em=myentitymanager
I get this output:
Processing entity "AppBundle\Entity\Offer"
Processing entity "AppBundle\Entity\Product"
I need to know if exist some argument or some way to create the entities in a subdirectory inside AppBundle/Entity.
So is any way to get this output?
Processing entity "AppBundle\Entity\Exampledir\Peticion"
Processing entity "AppBundle\Entity\Exampledir\Tecnologia"
Unfortunately the php bin/console doctrine:mapping:convert command does not accept a parameter to define the entity directory.
The target folder of the bundle has been hardcoded in the source code as:
if you choose annotation it's /Entity
if you choose xml, it's /Resources/config/doctrine
I'm getting started with Symfony2 and reading the book I got ot the doctrine entity generator code. Used the example in the book:
php app/console doctrine:generate:entity --no-interaction --entity="AppBundle:Category" --fields="name=string(255)"
and the new entity was created as expected, but I noticed that it generated some PHP code I'm not familiar with:
private $name=string(255);
and
public function setName=string(255)($name=string(255))
I've never seen before the string(255) when declaring a variable nor a function, and when I run
php app/console doctrine:generate:entities AppBundle
It throws an Fatal Parse Error on those lines. Removing the string(255) thing solves it. So, is it fine that Doctrine adds that code and my PHP interpreter's configuration is wrong? Doctrine shouldn't be adding that code or should I remove it after generating the entities? and finally, removing that code won't have consequences in the future?
Thanks,
If you look at the documentation for doctrine:generate:entity, you'll see that the format for declaring the fields looks actually like this:
... --fields="name:string(255)"
So you have to use a : (colon) to separate the field name of the type instead of an equal sign.
I'm trying to generate entities from existing tables in database, I keep getting the same error in a particular entity, which is imported from a second database (or entity manager), but I re-created this table in main database to use the same entity manager and get the same error, so I'm lost about what is happening.
This are my commands to generate it:
php app/console doctrine:mapping:convert yml ./src/MyShop/ProductBundle/Resources/config/doctrine/metadata/orm --from-database --filter="Product" --em=mysecondaryem
(BTW, is there a way to force exact filter? I only need Product)
Which seems to be ok:
Processing entity "ProductSold"
Processing entity "Product"
Exporting "yml" mapping information to...
Then
php app/console doctrine:mapping:import MyShopProductBundle annotation --em=mysecondaryem
Which is weird, as it is logging information about all other tables existing in this db but it's only generating the corresponding to "Product" as filtered (only the files ProductSold.php and Product.php do really exist):
Importing mapping information from "mysecondaryem" entity manager
> writing C:\mysite\src\MyShop\ProductBundle/Entity/ProductSold.php
> writing C:\mysite\src\MyShop\ProductBundle/Entity/Family.php
> writing C:\mysite\src\MyShop\ProductBundle/Entity/Category.php
> writing C:\mysite\src\MyShop\ProductBundle/Entity/Item.php
> writing C:\mysite\src\MyShop\ProductBundle/Entity/Stock.php
> writing C:\mysite\src\MyShop\ProductBundle/Entity/Product.php
Then, in the third step, I get an error:
php app/console doctrine:generate:entities MyShopProductBundle --no-backup
Generating entities for bundle "MyShopProductBundle"
[RuntimeException]
Bundle "MyShopProductBundle" does not contain any mapped entities.
doctrine:generate:entities [--path="..."] [--no-backup] name
As I sayed, I tried omitting secondary entity manager (replicating tables in my first database) and I get the same error.
You've verified that C:\mysite\src\MyShop\ProductBundle/Entity/Product.php has been created, but have you also checked that it actually contains mapped entities ?
Ok, I found the error, I was missing --force parameter, first step command should be:
php app/console doctrine:mapping:convert yml ./src/MyShop/ProductBundle/Resources/config/doctrine/metadata/orm --from-database --force --filter="Product" --em=mysecondaryem
I am using Symfony-2.0 and Propel 1.6.
For testing purposes I'd like to have separate schema file. The reason is that with my current schema it is impossible to load dumped fixtures, because process fails due PK and autoincrement:
app/console propel:fixtures:load --env=test
Use connection named default in test environment.
No SQL fixtures found.
No XML fixtures found.
[Propel] Exception
Cannot insert a value for auto-increment primary key (article.ID)
If I could define test_schema.xml I'd generate models from it without autoIncrement="true" property and then fixtures would be loaded.
How can I force Propel to use test_schema.xml in test environment?
Or may be there is another way how to load fixtures correctly?
You can use the propel propel.schema.dir and propel.default.schema.basename build properties to specify where the schema file is located and its name:
# app/config/config_test.yml
propel:
build_properties:
# The directory where Propel expects to find your `schema.xml` file.
propel.schema.dir = //wherever
# The schema base name
propel.default.schema.basename = schema