MYSQL: How to make NULL or empty data default to 0 during insert

前端 未结 5 2637
走了就别回头了
走了就别回头了 2021-02-20 01:07

So this seems like it would be pretty straight forward and I swear I\'ve done this before, but for some reason it\'s just not working for me.

I am using MAMP

5条回答
  •  野性不改
    2021-02-20 01:14

    You forgot to post the INSERT queries but I'm sure the problem is there. This works as expected:

    insert into listings (ListingID) values(1)
    

    ... because you omit BathsFull so MySQL uses the defalt. This doesn't:

    insert into listings (ListingID, BathsFull) values(1, null);
    

    ... because your are telling MySQL that you want NULL.

提交回复
热议问题