Database not in sync ( ALTER TABLE .... NOT NULL) #6527

Open
opened 2026-01-22 15:34:31 +01:00 by admin · 0 comments
Owner

Originally created by @procraste on GitHub (Aug 25, 2020).

Hi there,
I have the entity Reserver with custom types ( using carbon datetime library ) in it:

     /* @ORM\Column(type="carbon")
     * @var CarbonImmutable
     */
    private $debut;

validate-schem gives me "[OK] The mapping files are correct." but not in sync with database.

--dump-sql gives me:

ALTER TABLE reserver CHANGE jour jour datetime NOT NULL, CHANGE debut debut datetime NOT NULL, CHANGE fin fin datetime NOT NULL;

I can run directly the sql command and it gives me no error. The field are already not null in database.
This looks like an old bug with mariaDB. In fact, i fist test it with an old version of mariaDB.

But i tried also on a mysql 8 system and get the same error.

Here's how i configure the csutom carbon type:

<?php
namespace App\Library\Types;

use Carbon\CarbonImmutable;
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Platforms\AbstractPlatform;

/**
 * Type Doctrine: Datetime <---> Carbon.
 */
class CarbonType extends Type
{
    const CARBON = 'carbon';

    public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
    {
        return 'datetime';
    }

    public function convertToPHPValue($value, AbstractPlatform $platform)
    {
        return CarbonImmutable::parse($value);
    }

    public function convertToDatabaseValue($value, AbstractPlatform $platform)
    {
        return $value->toDateTimeString();
    }

    public function getName()
    {
        return self::CARBON;
    }
}

Everything else seems to work fine, i can retrieve/update/create entities.

Do you think it can be safe keeping this configuration ?
I can provide any precision if needed.
Thanks.

Originally created by @procraste on GitHub (Aug 25, 2020). Hi there, I have the entity Reserver with custom types ( using carbon datetime library ) in it: ```php /* @ORM\Column(type="carbon") * @var CarbonImmutable */ private $debut; ``` `validate-schem` gives me "[OK] The mapping files are correct." but **not in sync with database**. `--dump-sql` gives me: ```sql ALTER TABLE reserver CHANGE jour jour datetime NOT NULL, CHANGE debut debut datetime NOT NULL, CHANGE fin fin datetime NOT NULL; ``` I can run directly the sql command and it gives me no error. The field are already not null in database. This looks like an old bug with mariaDB. In fact, i fist test it with an old version of mariaDB. But i tried also on a mysql 8 system and get the same error. Here's how i configure the csutom carbon type: ```php <?php namespace App\Library\Types; use Carbon\CarbonImmutable; use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Platforms\AbstractPlatform; /** * Type Doctrine: Datetime <---> Carbon. */ class CarbonType extends Type { const CARBON = 'carbon'; public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) { return 'datetime'; } public function convertToPHPValue($value, AbstractPlatform $platform) { return CarbonImmutable::parse($value); } public function convertToDatabaseValue($value, AbstractPlatform $platform) { return $value->toDateTimeString(); } public function getName() { return self::CARBON; } } ``` Everything else seems to work fine, i can retrieve/update/create entities. Do you think it can be safe keeping this configuration ? I can provide any precision if needed. Thanks.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6527