Doctrine Schema Schema Updates Always Try to Add NOT NULL

I have a new installation of Symfony 2.8 with doctrine and MySQL 5.6.

After doing doctrine:schema:update --force , I see how Database schema updated successfully! "x" queries were executed Database schema updated successfully! "x" queries were executed

Here is my problem: even if I execute it several times, the doctrine always finds differences in the scheme.

With --dump-sql I see that all of these queries are related to:

  • adding NOT NULL to the row primary key
  • adding NOT NULL to the datetime field

However, when I check my database, these columns already have NOT NULL.

Here is an example of a single property / column:

 class MyEntity { /** * @ORM\Id * @ORM\Column(type="string", length=5, name="cd_key") * @ORM\GeneratedValue(strategy="AUTO") */ private $code; ... 

Here is the result of SHOW CREATE TABLE my_entity; :

 CREATE TABLE `my_entity` ( `cd_key` varchar(5) COLLATE utf8_unicode_ci NOT NULL, `label` varchar(255) COLLATE utf8_unicode_ci NOT NULL, `number` int(11) NOT NULL, PRIMARY KEY (`cd_key`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ; 

And here the request doctrine tries to execute the doctrine:schema:update command:

 ALTER TABLE my_entity CHANGE cd_key cd_key VARCHAR(5) NOT NULL; 
  • I clear my Symfony cache between each command.
  • I am trying to add nullable=false to the @Column annotation (an event if it is already defined as @Id), but no effect.
  • a doctrine:schema:validate does not find any display problem (other than synchronization).
  • I am trying to reset and recreate a complete database, but will fail.

Any ideas?

+6
source share
1 answer

I ran into a similar problem. For me, deleting the table using SQL and then starting again DOCTRINE:SCHEMA:UPDATE --FORCE worked for me.

It seems that doing some SQL queries manually is confusing the doctrine.

By saying this, I assume that you put @ORM\Table(name="my_entity") and @ORM\Entity(repositoryClass="myrepository") by the definition of your class;).

Hope this helps.

-one
source

Source: https://habr.com/ru/post/1015378/


All Articles