Voting starts in March for the Drupal Association Board election.
This page is for errors similar to the one below:
user error: Duplicate entry '24' for key 1 query: INSERT INTO node (status, moderate, promote, sticky, title, body, format, uid, created, type, teaser, changed, nid) VALUES('1', '0', '1', '0', 'test', 'this is a test', '1', '1', '1149692821', 'story', 'this is a test', '1149692832', '24') in .../includes/database.mysql.inc on line 66. warning: Cannot modify header information - headers already sent by (output started at .../includes/common.inc:384) in .../includes/common.inc on line 192.
The likely problem (short form): At some point, the sequence table in your Drupal database was not updated.
- Access your database. Check the affected table. In this case, the error tells us that it is the node table (query: INSERT INTO node). This also happens with other tables, modify these instructions accordingly.
- This is the node table, so the problem is the node id (nid). Each node has a unique id. Look at your table, and find the highest node id (nid). If you have many nodes, it may help to sort your table by nid to find the highest one.
- Go to your sequences table. Change the node id in the sequences table to a number higher than the id you found in step 2.
The problem (long form):
The 'key' in a table is a column where every entry has to be unique. For example, in the users table, every UID (user id number) must be unique. You don't want two users with the same id!
Drupal keeps track of what is the highest ID value separately, in the sequences table. When a new user is created, Drupal checks the sequences table to find out what the next UID should be. Presumably this is more efficient than checking the user table itself. Drupal then creates the new user, updates the user table with the new user information, and updates the sequences table with the new UID. The same thing happens for the node table, comment table, really, a whole bunch of tables.
Sometimes, for some reason, Drupal does not update the sequence table. The number there becomes out of date. So let's say that in the node table the highest NID is 300, but somewhere, something went wrong, and in the sequences table, the NID is only 297. The next time Drupal makes a node, it will check the sequences table, and try to make a node with a NID of 298...whoops! That already exists.
The solution (long form):
The error itself can tell us a lot. Let's divide it into 3 parts:
user error: Duplicate entry '24' for key 1
Duplicate... meaning the '24' is the same as something else in the table, something where no two things can be the same. Which table? Which column?
query: INSERT INTO node (status, moderate, promote, sticky, title, body, format, uid, created, type, teaser, changed, nid)
INSERT INTO [tablename] tells us which table produced the error. What follows is a list of column names.
VALUES('1', '0', '1', '0', 'test', 'this is a test', '1', '1', '1149692821', 'story', 'this is a test', '1149692832', '24') in .../includes/database.mysql.inc on line 66.
The values we tried to insert into columns of the NODE table... We already know '24' was the problem, we see here it is the LAST value, corresponding to the LAST column, the nid, or node id.
So the problem is, we tried to insert 24 into the nid column of the node table, when that value already existed (duplicate entry!).
Why? Because the sequence table was not updated, and told Drupal the wrong nid. The solution is to enter a value for nid into the sequence table that is higher than ANY nid in the node table.
To find the highest nid in the node table, access your database, however you do it. Find the node table, and sort it by nid. Write down the highest value. Let's say for this example that the highest number is 68.
Go to the sequences table, and find the row that has nid in it. Replace the number there with ANY number higher than the highest value in the node table. For this example, the highest value was 68. 69 would work, so would 70, 90, and 201. ANY NUMBER higher than 68 would work in this example.
Additional point: 99% of the time, the solution is in the sequence table, but this error will come up ANY time you try to insert duplicate data into a column where every value has to be unique.