Home > database >  Strange Duplicate entry '0' for key 'PRIMARY' problem! ~
Strange Duplicate entry '0' for key 'PRIMARY' problem! ~

Time:11-07

A data table id, name, the value of which id is the primary key, and the growth,

A circular insert statement,

Insert into the db (` name `, ` value `) VALUES (' jack ', 'welcome')

With no problem, today on a win2008 system to run the program, tip:
Duplicate entry '0' for key 'PRIMARY'
A mystery!!!!!!!!!!

Using statements in your phpmyadmin insert directly, no problem, but the application running, too, will prompt the Duplicate entry '0' for key 'PRIMARY'!

Why???????

CodePudding user response:

Primary key repeat, look at the code is not generated on the primary key

CodePudding user response:

Print out look at the SQL in the program

CodePudding user response:

Insert into the db (` id `, ` name `, ` value `) VALUES (null, 'jack', 'welcome');

CodePudding user response:

Innodb tables? Is inserted before restart the database?

CodePudding user response:

Program has a place to set by default to 0

CodePudding user response:

See sql_mode variable is used NO_AUTO_VALUE_ON_ZERO, using only the NULL can be generated by a sequence number

CodePudding user response:

Check what's the difference between two machines of SQL mode,

CodePudding user response:

Support the fifth floor's point of view, the program have a place to put the value of the initial value is set to 0,

CodePudding user response:

Table AUTO_INCREMENT isn't be changed

CodePudding user response:

Now that is on the primary key, then don't in the program into the button, the other fields should be no problem

CodePudding user response:

Program has a place to set the value of the initial value to 0,

CodePudding user response:

Innodb_autoinc_lock_mode=2

CodePudding user response:

The specification of [1] innodb_autoinc_lock_mode

Innodb_auto_lockmode has three values:
1, 0 this tradition traditional
2, 1 the said consecutive continuous
3, 2, the said interleaved
  • Related