0

I have a column on my mysql table that is currently VARCHAR, it is named logcount.

Upon user creation the logcount is set to nothing, and once the account is verified it sets itself to 0. If a user tries to login when it is empty it urges them to verify there account. Once verified it is set as 0, and everytime the user logs in it adds 1 to it.

The reason it is set to VARCHAR is because if I set it to INT, mysql automatically sets it to 0 and will not let me have a blank value for it. Is there any setting that I can make this possible. And will having a column set to VARCHAR that will only ever contain an INT be a problem?

2 Answers 2

1

Is there any setting that I can make this possible.

Tell MySQL to default it to NULL:

ALTER TABLE sometable MODIFY logcount INT DEFAULT NULL;

And will having a column set to VARCHAR that will only ever contain an INT be a problem?

One issue pertains to columns that are intended to be indexed... integer columns work much better as indexes than string columns.

Sign up to request clarification or add additional context in comments.

Comments

0

No 'real' problem with the varchar...just smells bad. I would guess that your column is set to not nullable. Change it to a nullable column and set it to "null" instead of "nothing" as you say.

An alternative would be to set it to -1, and then test for this in your code. Only add 1 if it is >= 0.

1 Comment

This is a great alternative! Thanks for this!

Your Answer

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.