Subba Rao
Subba Rao

Reputation: 10676

MySQL inserting rows with 0 value in primary key

MySQL (v5.41) on Ubuntu is inserting rows with primary key value as 0.

Below is the MySQL table data.

mysql> select id from keywords where text_id = 72;
+----+
| id |
+----+
|  0 |
|  0 |
+----+

| keywords | CREATE TABLE `keywords` (
  `id` int(11) NOT NULL DEFAULT '0',
 `to_user_id` bigint(20) DEFAULT NULL,
  `text_id` int(11) DEFAULT NULL
  ) ENGINE=MyISAM DEFAULT CHARSET=latin1 |

+--------+---------------------------------

Upvotes: 0

Views: 3193

Answers (2)

Gaurav
Gaurav

Reputation: 28755

set the primary key column to AUTO INCREMENT also.

Like

CREATE TABLE table (
     id INT NOT NULL AUTO_INCREMENT,
     name CHAR(30) NOT NULL,
     PRIMARY KEY (id)
) ENGINE=MyISAM;

Upvotes: 2

Tudor Constantin
Tudor Constantin

Reputation: 26861

You probably don't have the field id as AUTOINCREMENT

Upvotes: 0

Related Questions