Я работаю со следующим кодом:
Код: Выделить всё
#[Entity]
#[Table(name: 'messages')]
class Message
{
#[Column(name: 'sent_at', type: Types::DATETIME_IMMUTABLE, updatable: false, options: ['default' => 'CURRENT_TIMESTAMP'])]
private readonly DateTimeImmutable $sent_at;
...
}
Код: Выделить всё
CREATE TABLE messages (
id int unsigned AUTO_INCREMENT NOT NULL,
sent_at datetime DEFAULT CURRENT_TIMESTAMP NOT NULL,
message text NOT NULL,
PRIMARY KEY (id)
);
Код: Выделить всё
$message = new Message($message);
$this->entity_manager->persist($message);
$this->entity_manager->flush();
Код: Выделить всё
Uncaught PDOException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'sent_at' cannot be null in vendor/doctrine/dbal/src/Driver/PDO/Statement.php:55Я бы не хотел устанавливать send_at вручную< /code> в конструкторе, если это возможно.
Код: Выделить всё
"doctrine/orm": "^3.0",
"doctrine/dbal": "^4.0",
вывод SELECT VERSION();: 10.4.28-MariaDBЕсли быть точным, причина где-то в PHP/Doctrine, потому что
Код: Выделить всё
INSERT INTO `messages` (`message`) VALUES ('message')
Подробнее здесь: https://stackoverflow.com/questions/791 ... ot-working
Мобильная версия