How to force MySQL to take 0 as a valid auto-increment value

From the answer I got here:

You can use:

SET [GLOBAL|SESSION] sql_mode="NO_AUTO_VALUE_ON_ZERO"

Which as described here, will prevent MySQL from interpreting an INSERT/UPDATE ID of 0 as being the next sequence ID. Such behaviour will be limited to NULL.

It is what I’d consider pretty bad behaviour from the application though. You’ll have to be real careful that it’s used consistently, especially if you choose to implement replication at a later date.

Leave a Comment