Monday, December 2, 2013

[SQL][solved] Duplicate entry '0' for key 'PRIMARY'


Since your primary key field haven’t set as auto-increase, if an insert SQL would insert a record with no id value (default would insert value 0), it causes error.

Solution:
ALTER TABLE your_table_name MODIFY COLUMN your_column dataType AUTO_INCREMENT ;
use my case be an example:
ALTER TABLE tbl_section MODIFY COLUMN id INT(11) NOT NULL AUTO_INCREMENT ;


Reference:
http://stackoverflow.com/questions/2169080/mysql-alter-a-column-to-be-auto-increment

No comments :

Post a Comment