I'm using doctrine in combination with symfony. For the database setup I'm using annotations. I created a table successfully but gave the wrong format integer
for a field city
which I need to change to string
. My understanding was, that when I'm changing the annotations in the customers class from
class Customer{
/**
* @ORM\Column(type="integer", nullable=true)
* @var string city
*/
private $city;
}
to
class Customer{
/**
* @ORM\Column(nullable=true)
* @var string city
*/
private $city;
}
and then run
php bin/console doctrine:migrations:diff
all changes of the mapping should be recognized and a php file should be generated containing an ALTER TABLE query or similar. However, this command replies with a "No changes detected in your mapping information". What am I missing?
In my case, I had to add the --from-empty-schema flag.
doctrine:migrations:diff --from-empty-schema
I needed to first clear the cache with
php bin/console doctrine:cache:clear-metadata
Success!
You should add the annotation @Entity
to the entity to be recognized as an entity in doctrine ORM.
<?php
/**
* Customer
*
* @ORM\Table(name="customers")
* @ORM\Entity(repositoryClass="YourBundle/Repository/YourRepositoryName")
*/
class Customer{
/**
* @ORM\Column(type="string", nullable=true)
* @var string city
*/
private $city;
}
You can also use this command to auto-generate entities with different required annotations:
bin/console doctrine:generate:entity
This can also happened when your mapping is invalid.
A quick workaround would be to do
php bin/console doctrine:schema:validate
Then fix errors until you see
[OK] The mapping files are correct.
Now make php bin/console doctrine:migrations:diff
again and it should work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With