4

Hi i'm working laravel 5 with mysql. I did store zipcode into my database it working well but when the field is empty it stored zero(0) but i want to store empty value in database.

I'm also changed mysql using alter table like below ALTER TABLE insurances CHANGE COLUMN zipcode4 zipcode4 int(4) unsigned DEFAULT NULL; but it wont work, have any idea ?

Thanks in advance

asked Aug 22, 2015 at 7:45

3 Answers 3

3

Well, zipcode is something which has fixed characters, and wont need any arithmetic operations so,

  1. You can change the datatype to CHAR or VARCHAR

  2. Forcefully insert NULL value while inserting query !

Try This,

3.

 ALTER TABLE insurances CHANGE zipcode4 zipcode4 int(4) DEFAULT NULL;
answered Aug 22, 2015 at 7:52

2 Comments

I tried this alter query and insert null value when insert but it also store zero only..
plz run these queries and show the proper output in Question area ; SELECT @@version; SHOW CREATE TABLE insurances;
0

the prevous default were 0, so after changing the default they still keep it, to update it after having changed the default, do something like:

UPDATE mytable set zipcode4=NULL WHERE zipcode4=0

the new values will correctly put NULL if not value is provided

answered Mar 31, 2017 at 8:37

Comments

-2

100 % accuracy this code

UPDATE mytable SET zipcode4 = NULL WHERE zipcode4 = 0
UPDATE mytable SET Myfield = NULL WHERE Myfield = 0
ilkerkaran
4,3723 gold badges30 silver badges45 bronze badges
answered Sep 5, 2018 at 20:07

1 Comment

Why would someone just copy another answer from 18 months previous? What is the point?

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.