3

I have scoured the internet, books and forums looking for an answer to this, and am hoping someone on here can help.

I have a standard Symfony 2 project setup, using entity annotations in doctrine. The problem I have is that any of my entities that contain a datetime type constantly want to migrate. So after initial migration to the db i can re run docrine:schema:update --dump-sql and I still see this:

ALTER TABLE log CHANGE date date DATETIME NOT NULL;
ALTER TABLE message CHANGE created_on created_on DATETIME NOT NULL, CHANGE updated_on updated_on DATETIME NOT NULL;
ALTER TABLE module CHANGE start_date start_date DATETIME DEFAULT '0000-00-00 00:00:00' NOT NULL, CHANGE end_date end_date DATETIME NOT NULL;
ALTER TABLE scheduled_commands CHANGE last_execution last_execution DATETIME NOT NULL;

I could sit here all day running migrations and checking this and it will stay the same. The entities have nothing special in them either:

  /**
  * @var \DateTime
  *
  * @ORM\Column(name="start_date", type="datetime")
  */
 private $startDate;

 /**
 * @var \DateTime
 *
 * @ORM\Column(name="end_date", type="datetime")
 */
 private $endDate;

Does anyone have any ideas on this? I am now completely stumped :( .

The mysql setup is current 5.6.25 too

the columns structure look like this once migrated

`start_date` | DATETIME | NOT NULL,
`end_date` | DATETIME | NOT NULL
gristoi
  • 161
  • 2
  • 7
  • And what does executing them do? Can you provide the current table schema for these tables? – Gerry Oct 16 '15 at 15:13
  • im afraid the whole table structure etc is work sensitive, so i cant put online. But this is the snippet from the db relating to the above entity :but migrating just runs as expected, the star_date and end_date fields both have a datetime type with Not Null status. and as expected nothing has changed in the db as these fields have been set – gristoi Oct 16 '15 at 15:16
  • can you try ALTER TABLE log CHANGE `date` `date` DATETIME NOT NULL; date is reserved word in mysql. Try " ` " with all field into your migration – rommct Oct 16 '15 at 15:20
  • I have 12 other entities , all with varying names, that are datetime types that are having this issue, a lot of them dont have date in the field name – gristoi Oct 16 '15 at 15:34
  • Before any doctrine migrate diff command run `cache:clear', 'cache:warm' and restart php. Ex: $ php app/console c:c && php app/console c:w && sudo service php5-fpm restart – jcroll Oct 16 '15 at 15:51
  • Have tried your suggestion, still having the same issue. – gristoi Oct 16 '15 at 15:56
  • I have the same problem, did you solve it? – Jose Celano Sep 02 '16 at 08:57
  • 2
    Almost two years elapsed since the previous comment, and I still have this issue in Symfony 4. – ob-ivan Aug 04 '18 at 19:30
  • I'm having this exact problem. I ran the query manual, and it still appears in the next migration – Martijn Jun 17 '19 at 09:15

1 Answers1

0

You need to ensure that types.datetime is correctly set up in doctrine.yaml