Steps in generating entity - symfony

I need help to generate entity, because when I tried the below one I get errors.
Create databse:
php app/console doctrine:database:create
Generate entity:
php app/console doctrine:generate:entity
Generate the Getters and Setters:
php app/console doctrine:generate:entities AiQABlogBundle/Entity/Profile
The above step gives this error:
[RuntimeException]
Namespace "AiQABlogBundle\Entity\Profile" does not contain any mapped entities.

In this post you find answer
Or You should enter this command
php app/console doctrine:generate:entities AiQABlogBundle:Profile

Related

Cannot generate Entity from existing Oracle DB

Following symfony's documentation to create entities from exiting database,I get an error when running the first command:
php bin/console doctrine:mapping:import --force AppBundle yml
The error is:
[Symfony\Component\Debug\Exception\ContextErrorException]
Warning: file_put_contents(C:\WebApp\src\AppBundle/Resources/config/doctrine/"user".orm.yml): failed to open stream: Invalid argument
How can I fix it?
Looks like User is a reserved word within Oracle databases, so when I created the table, Oracle created a table named "user" with double quotes. So when trying to generate the entity, doctrine cannot find the table user and found an invalid argument "user" with double quotes in it. The way I solved the problem is by using another name other than user.
Hope this helps someone on the future.
php bin/console doctrine:mapping:import --force AppBundle yml
change to
php bin/console doctrine:mapping:import AppBundle yml --force
more details:
The doctrine:mapping:import command imports mapping information
from an existing database:
php app/console doctrine:mapping:import "MyCustomBundle" xml
You can also optionally specify which entity manager to import from with the
--em option:
php app/console doctrine:mapping:import "MyCustomBundle" xml --em=default
If you don't want to map every entity that can be found in the database, use the
--filter option. It will try to match the targeted mapped entity with the
provided pattern string.
php app/console doctrine:mapping:import "MyCustomBundle" xml --filter=MyMatchedEntity
Use the --force option, if you want to override existing mapping files:
php app/console doctrine:mapping:import "MyCustomBundle" xml --force

Specify entity name while generating from existing database table symfony2

I've a database table users and I want to generate its entity in my symfony2 bundle KapCrudBundle.
I'm using the following commands:
php app/console doctrine:mapping:convert yml ./src/Kap/CrudBundle/Resources/config/doctrine/metadata/orm --from-database --force --filter=Users
php app/console doctrine:mapping:import KapCrudBundle annotation --filter=Users
php app/console doctrine:generate:entities KapCrudBundle
These all above commands working absolutely fine but I want to do the following things:
It's generating the entity Users.php and annotation file Users.orm.yml because my table name is users but I want the entity name and annotation files like User.php and User.orm.yml
Second thing is that it generates all entities again in the bundle but I want only the User entity to generate.
Regarding the 2nd question: you can simply specify the entity.
php app/console doctrine:generate:entities KapCrudBundle/Entity/User

Symfony2 "php app/console doctrine:schema:update --force" doens't add a column to table

I am trying to add a column to a table through doctrine command:
php app/console doctrine:schema:update --force
I know it can do that, since I've done that before and documentation states that clearly:
"In other words, if you add a new property with mapping metadata to Product and run this task again, it will generate the "alter table" statement needed to add that new column to the existing product table."
The following is the field I'm trying to add as a column:
/**
* #var string
*
* #ORM\Column(name="service_machine_name", type="string", length=40, nullable=false)
*/
private $serviceMachineName;
But when I type:
php app/console doctrine:schema:update --force
It tells me that my database is in sync with my current entity, but it clearly is not, because I have an additional field in my entity class.
I also tried shortening the column name to 3 letters (just in case), but it still doesn't add a column!
Note: I have added columns to a different table on the same database (which is remote) and it worked fine before.
You have to first create setter and getter for that columns like this
php app/console doctrine:generate:entities Acme/DemoBundle/Entity/User
after that you have to use
php app/console doctrine:schema:update --force
This answer is correct: https://stackoverflow.com/a/22198323/2400373
But don't work in symfony 3, for this version is necessary a change, the code is:
You have to first create setter and getter for that columns like this
php bin/console doctrine:generate:entities Acme/DemoBundle/Entity/User
after that you have to use
php bin/console doctrine:schema:update --force

doctrine:generate:entities vs generate:doctrine:entities in Symfony2 console

What are the differences between
doctrine:generate:entities vs generate:doctrine:entities
the description for both is the same
Generates entity classes and method stubs from your mapping information
They are the same.
generate:doctrine:entities is an alias to doctrine:generate:entities
In the DoctrineBundle source code it is coded as:
...
$this
->setName('doctrine:generate:entities')
->setAliases(array('generate:doctrine:entities'))
...
Source code link.

Update schema just from yml in Symfony2 with Doctrine

I want to add an item like this just to the src/Acme/AdminBundle/Entity/Artist.orm.yml:
email:
type: string
column: email_address
length: 150
but I'm forced to do the same in the file Acme/AdminBundle/Entity/Artist
/**
* #var string $email
*/
private $email;
If I don't do it, when I update the schema it shows an error:
php app/console doctrine:schema:update --force
[Doctrine\ORM\Mapping\MappingException]
An error occurred in Acme\AdminBundle\Entity\Artist
[ReflectionException]
Property email does not exist
I generated the Bundle with the yml option at the beginning.
First, generate the entity class file
php app/console doctrine:generate:entities [Your]/[Bundle]/Entity/Artist --path="src/" --no-backup
The "--path" param must be given if there is a new entity to be generated.
Then, update your schema:
php app/console doctrine:schema:update --force
I had the same problem and I managed to solve it.
doctrine:generate:entity generates the .php entity file at "Entity" but it also generates a orm file at "Resources/config/doctrine" which can create conflicts if you modify the .php entity file.
I just deleted the orm files and it works as expected.

Resources