How to store NULL values in datetime fields in MySQL?

后端 未结 8 528
再見小時候
再見小時候 2020-11-29 05:44

I have a \"bill_date\" field that I want to be blank (NULL) until it\'s been billed, at which point the date will be entered.

I see that MySQL does not like NULL val

8条回答
  •  一整个雨季
    2020-11-29 06:19

    It depends on how you declare your table. NULL would not be allowed in:

    create table MyTable (col1 datetime NOT NULL);
    

    But it would be allowed in:

    create table MyTable (col1 datetime NULL);
    

    The second is the default, so someone must've actively decided that the column should not be nullable.

提交回复
热议问题