Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

doctrine:migrations:diff give "No changes detected in your mapping information"

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?

like image 785
agoldev Avatar asked Jan 15 '18 08:01

agoldev


4 Answers

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

doctrine:migrations:diff --from-empty-schema
like image 115
Roy Avatar answered Nov 03 '22 08:11

Roy


I needed to first clear the cache with

php bin/console doctrine:cache:clear-metadata 

Success!

like image 25
agoldev Avatar answered Nov 03 '22 08:11

agoldev


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
like image 8
T. AKROUT Avatar answered Nov 03 '22 07:11

T. AKROUT


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.

like image 5
Greco Jonathan Avatar answered Nov 03 '22 08:11

Greco Jonathan