Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony Doctrine schema update not detecting changes with nullable datetime

When I run this command at first, everything seems to work fine :

$ php bin/console doctrine:schema:update --dump-sql
ALTER TABLE posts CHANGE createdAt createdAt DATETIME NOT NULL, CHANGE updatedAt updatedAt DATETIME DEFAULT NULL;

$ php bin/console doctrine:schema:update --force
Updating database schema...
Database schema updated successfully! "1" query was executed

But when I re-run a dump-sql, it's like the update hasn't happened :

$ php bin/console doctrine:schema:update --dump-sql
ALTER TABLE posts CHANGE createdAt createdAt DATETIME NOT NULL, CHANGE updatedAt updatedAt DATETIME DEFAULT NULL;

I can repeat that endlessly.

Here is my Post entity with the createdAt and updatedAt properties annotations :

<?php

namespace WebBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * Post
 *
 * @ORM\Table(name="posts")
 * @ORM\Entity(repositoryClass="WebBundle\Repository\PostRepository")
 */
class Post
{
    ...

    /**
     * @var \DateTime
     *
     * @ORM\Column(name="createdAt", type="datetimetz")
     */
    private $createdAt;

    /**
     * @var \DateTime
     *
     * @ORM\Column(name="updatedAt", type="datetimetz", nullable=true)
     */
    private $updatedAt;

And when I check my MariaDB table, the schema is exactly what I declared :

# Name      Type      Collation Attributes  Null  Default Extra
1 id        char(36)                        No    None
...
7 createdAt datetime                        No    None
8 updatedAt datetime                        Yes   NULL

Any idea about what's wrong ?

like image 806
Edouard Hienrichs Avatar asked Oct 31 '22 00:10

Edouard Hienrichs


1 Answers

i Have exactly the same problem !

I rename the field type "datetimez" to "datetime" and now it is ok

    /**
 * @var \DateTime
 *
 * @ORM\Column(name="created", type="datetime")
 */
private $created;
like image 105
fli27 Avatar answered Nov 09 '22 17:11

fli27