14

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?

2
  • @ORM\Column(type="string")
    – habibun
    Commented Jan 15, 2018 at 8:32
  • type string is default. However, I tried your suggestion but the behavior remains the same.
    – bln_dev
    Commented Jan 15, 2018 at 8:33

9 Answers 9

34

I needed to first clear the cache with

php bin/console doctrine:cache:clear-metadata 

Success!

0
8

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
1
  • 3
    Sorry, I failed to give the full code. Of course there is the Entity annotation in my code.
    – bln_dev
    Commented Jan 15, 2018 at 9:10
5

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.

3

In my case, I had to add the --from-empty-schema flag.

doctrine:migrations:diff --from-empty-schema
2

In my case, i had mapping type 'attribute' in doctrine config file, but entity had annotations.

0

if you are using a complicated Symfony configuration check doctrine.orm.entity_managers.default.mappings config values in config.yml. Probably you have to add your new bundle here when it's not work.

0

In case it can help others, for me it was just a matter of a wrong namespace set in my entity class.

I had duplicated an entity from another package and forgot to update the namespace.

0

My problem was that I had placed my entity in bundle Doctrine folder but had to place it into Entity folder.

0

Similar to @agoldev I needed to clear the cache. Just not the doctrine metadata cache but the symfony cache. But he lead me to find this solution.

php bin/console cache:clear

Then it worked.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.