After upgrading Drupal and the plugin from an older version, any attempt to create new content results in an error message like the following:

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '305-node' for key 'PRIMARY': INSERT INTO {ip_posts} (type, id, ip) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2); Array ( :db_insert_placeholder_0] => node [:db_insert_placeholder_1] => 305 [:db_insert_placeholder_2] => ip_value_removed ) in ip_posts_insert() (line 330 of /site/path/public_html/sites/all/modules/ip/ip.module).

I found an earlier report of someone experiencing similar which was resolved by removing the module after disabling the module, then re-adding the module. I have tried this with no success. I assume that clearing the IP values would probably resolve this issue, but it should be possible to upgrade the module without needing to clear historic IP data.

Comments

Savet’s picture

Issue summary: View changes
Savet’s picture

Issue summary: View changes

Removed several sensitive pieces of information.

Savet’s picture

I was able to resolve the conflict by truncating the ip_posts table and leaving the ip_tracker table intact. All IP data appears to be retained.

Savet’s picture

This issue has reappeared after a period of time with no changes to code or module versions.

hfortune’s picture

This issue is happening on my sites as well. We had the issue crop up last week. This issue completely disables the entire website, erroring out any attempt at new content. There is a similar error that affects comments as well, pretty much rendering the entire website useless :(

I did truncate the tables as suggested above. I run about 30 websites and all of them were having this issue. I truncated their ip_posts tables last week. We are already having occurrence of this issue. I have truncated two tables this morning and will likely just go through and truncate each sites' ip_posts table again so they do not lose functionality.

This is a major major bug. Please let me know what I can provide to you to help with resolving it.

Here is one of our most recent error messages from this morning:

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '25922-node' for key 'PRIMARY': INSERT INTO {ip_posts} (type, id, ip) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2); Array ( [:db_insert_placeholder_0] => node [:db_insert_placeholder_1] => 25922 [:db_insert_placeholder_2] => 1827252900 ) in ip_posts_insert() (line 162 of /home/heather/public/yourcitymommies.com/public/sites/all/modules/ip/ip.module).

hfortune’s picture

I cleaned out the ip_post tables last week after posting my comment above. We started getting the error again today, so I had to truncate that table again. Is anyone else experiencing this error? It basically stops any new content from being created until the table is cleaned out again.

Thanks
Heather

srikanth.g’s picture

Blog and comment modules are enabled and working fine in my Drupal 7.34 site,but after 1 month when users are trying to post comments it shows errors:
PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry for key 'PRIMARY': INSERT INTO {ip_posts} (type, id, ip) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2); Array ( [:db_insert_placeholder_0] => comment [:db_insert_placeholder_1] => 3 [:db_insert_placeholder_2] => 1868414682 ) in ip_posts_insert() (line 330 of sites\all\modules\ip\ip.module).
The website encountered an unexpected error. Please try again later.

PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'cache_rules' doesn't exist: TRUNCATE {cache_rules} ; Array ( ) in cache_clear_all() (line 167 of \includes\cache.inc).

I am using many ip address related modules like IP,IP_RANGES,IP2COUNTRY to ban access to a Country/single IP-address. Truncating "ip_posts" table will fix the issue?

hfortune’s picture

This error still happens frequently on my network of drupal websites -- I have had to truncate the table twice this week to allow people to be able to add content on our websites.

Is there any resolution for this bug?

GeduR’s picture

Status: Active » Postponed (maintainer needs more info)

Please, could you try with the last 7.x-2.x version? I think that the cron process was involved which is now removed.

hfortune’s picture

I just wanted to come back and report that I am using the 7.x-2.x-beta1 version on my websites and I am still experiencing this issue. The only way to resolve it is to run a truncate command on the ip_posts table. It does stop anyone from posting or commenting until the table is truncated.

antims’s picture

Same errors with 7.x-2.x-beta1.

nibsniven’s picture

This module doesn't handle node deletion properly because it does not know when nodes are deleted.
Try adding this to ip.module:

----------------------------------------------------------------------------------------
/**
* Implements hook_node_delete()
*/
function ip_node_delete($node) {
db_delete('ip_posts')->condition('id', $node->nid)->execute();
}
----------------------------------------------------------------------------------------

This should prevent the problem from reoccurring.

To stop an existing issue, you can truncate the ip_posts table, or you can just delete any IDs at and above the ID giving the issue:
DELETE FROM ip_posts WHERE id>=1066;

EDIT: Another issue is that the ip_posts table also tracks comments, so when a node is deleted, the comments for that node need to be deleted too. The MySQL way to delete the comment entries in ip_posts is:

DELETE FROM ip_posts WHERE id IN (SELECT cid FROM comments WHERE nid={$node->nid});

I could write the code to do that the Drupal Way, but to be frank I really don't see why I should bother since it's obvious the developer has abandoned this module.

sagesolutions’s picture

Status: Postponed (maintainer needs more info) » Closed (outdated)