0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

1292 Incorrect datetime value: '0000-00-00 00:00:00'のエラー

Posted at

エラーが出て困ったのでメモです。
symfonyは自動でcreated_atやupdated_atが入らないようです。
idは入りましたが。

僕のローカルのmysqlが'0000-00-00 00:00:00'を許さない設定のようでこうなったようです。

実際のプロダクトだとmysqlの設定を変えるのがよさそうですが、今回はローカルだけの勉強用なので、簡単にこうしました。

[error] Migration DoctrineMigrations\Version20xxxxxxxx failed during Execution. Error: "An exception occurred while executing a query: SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: '0000-00-00 00:00:00' for column 'created_at' at row 1"
An exception occurred while executing a query: SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: '0000-00-00 00:00:00' for column 'created_at' at row 1     

僕は、typeをdatetime_immutableからdatetimeにしてやったらうまくいきました。

% symfony console make:entity XxxxXXX

 Your entity already exists! So let's add some new fields!

 New property name (press <return> to stop adding fields):
 > created_at

 Field type (enter ? to see all types) [datetime_immutable]:
 > datetime

 Can this field be null in the database (nullable) (yes/no) [no]:
 > 

参考
https://qiita.com/77web@github/items/158540fd4c1e379d1e9d

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?