Simple Machines Community Forum

SMF Support => SMF 2.0.x Support => Topic started by: stray_tachyon on February 09, 2025, 12:24:10 PM

Title: Uncaught mysqli_sql_exception: Duplicate entry '16777215' for key 'PRIMARY' in /
Post by: stray_tachyon on February 09, 2025, 12:24:10 PM
Hi all.
I'm running SMF version 2.0.18 on the site http://www.china-defense.com/smf/index.php.  The software is returning HTTP 500 errors and the following is in the error_log:

[04-Feb-2025 20:17:53 Etc/GMT+5] PHP Fatal error:  Uncaught mysqli_sql_exception: Duplicate entry '16777215' for key 'PRIMARY' in /home2/cdf/public_html/smf/Sources/Subs-Db-mysql.php:1169
Stack trace:
#0 /home2/cdf/public_html/smf/Sources/Subs-Db-mysql.php(1169): mysqli_query(Object(mysqli), '\n\t\t\tINSERT INTO...')
#1 /home2/cdf/public_html/smf/Sources/Subs-Db-mysql.php(1497): SMF_DB_MySQLi->query('', '\n\t\t\tINSERT INTO...', Array, Object(mysqli))
#2 /home2/cdf/public_html/smf/Sources/Errors.php(139): SMF_DB_MySQLi->insert('', 'smf2009_log_err...', Array, Array, Array)
#3 /home2/cdf/public_html/smf/Sources/Errors.php(161): log_error('Duplicate entry...', 'general')
#4 /home2/cdf/public_html/smf/index.php(130): fatal_error('Duplicate entry...', 'general')
#5 [internal function]: {closure}(Object(mysqli_sql_exception))
#6 {main}


Using the phpMyAdmin, I deleted the entry in the smf2009_log_errors with id_error = 16777215.  However, every time someone visited the site, the same entry with id_error = 16777215 gets created again and again.

I'm at a lost why this is happening.  I couldn't figure out why it is happening.  Can you please give me some guidance on how to fix it?

Thank you very much.
Title: Re: Uncaught mysqli_sql_exception: Duplicate entry '16777215' for key 'PRIMARY' in /
Post by: vbgamer45 on February 09, 2025, 12:49:21 PM
Try to change the autoincreament field on the table to a higher id.

Or a quick fix disable error logging.  in smf_settings find
enableErrorLogging and set the value to 0
Title: Re: Uncaught mysqli_sql_exception: Duplicate entry '16777215' for key 'PRIMARY' in /
Post by: shawnb61 on February 09, 2025, 01:06:15 PM
16M errors is a lot...  id_error is a MEDIUMINT...

The largest value an unsigned MEDIUMINT can hold is 16,777,215.

I'd probably change it to an INT, & try to figure out where all the errors are coming from.
Title: Re: Uncaught mysqli_sql_exception: Duplicate entry '16777215' for key 'PRIMARY' in /
Post by: stray_tachyon on February 09, 2025, 01:15:22 PM
Thank you very much.

I have ran "alter table smf2009_log_errors auto_increment = 16777216;", didn't help
I have also changed id_error to mediumint(20)
Neither changes helped.

In the Settings.php, there is an entry:
$db_last_error = 1607014351;
Changing it to "$db_last_error = 160701435100000;" and adding "$enableErrorLogging = 0;" didn't help either.

Title: Re: Uncaught mysqli_sql_exception: Duplicate entry '16777215' for key 'PRIMARY' in /
Post by: shawnb61 on February 09, 2025, 01:16:26 PM
mediumint(20) won't work, it's still a mediumint.

It needs to become an int.

And you need to figure out how you got 16M+ errors.
Title: Re: Uncaught mysqli_sql_exception: Duplicate entry '16777215' for key 'PRIMARY' in /
Post by: stray_tachyon on February 09, 2025, 02:05:58 PM
Quote from: shawnb61 on February 09, 2025, 01:16:26 PMmediumint(20) won't work, it's still a mediumint.

It needs to become an int.

And you need to figure out how you got 16M+ errors.

I just got pulled in to fix the forum :)

Changed the column to int and we are back in business!!! :D

Thank you thank you thank you!!!

is it safe for me to run "delete from smf2009_log_errors"?

This is an example record in the smf2009_log_errors table:
url:
?action=verificationcode;vid=register;rand=<deleted>

message:
8192: imagefilledpolygon(): Using the $num_points parameter is deprecated

file:
/home2/cdf/public_html/smf/Sources/Subs-Graphics.php

line:
917
Title: Re: Uncaught mysqli_sql_exception: Duplicate entry '16777215' for key 'PRIMARY' in /
Post by: vbgamer45 on February 09, 2025, 02:17:23 PM
What PHP version are you on? Also you should up to at least 2.0.19...
Title: Re: Uncaught mysqli_sql_exception: Duplicate entry '16777215' for key 'PRIMARY' in /
Post by: stray_tachyon on February 09, 2025, 03:23:57 PM
Quote from: vbgamer45 on February 09, 2025, 02:17:23 PMWhat PHP version are you on? Also you should up to at least 2.0.19...

Look to be 5.2.1 according to phpMyAdmin help but PHP 8.2 (ea-php82)  according to the hosting company's control panel

Can I upgrade to 2.1.4?

Thanks
Title: Re: Uncaught mysqli_sql_exception: Duplicate entry '16777215' for key 'PRIMARY' in /
Post by: Sir Osis of Liver on February 09, 2025, 03:36:05 PM
2.0.18 does not support php 8.  Yes, you should upgrade to current version. 
Title: Re: Uncaught mysqli_sql_exception: Duplicate entry '16777215' for key 'PRIMARY' in /
Post by: Kindred on February 09, 2025, 05:14:08 PM
Also,  clear your error log
Title: Re: Uncaught mysqli_sql_exception: Duplicate entry '16777215' for key 'PRIMARY' in /
Post by: stray_tachyon on February 09, 2025, 05:36:50 PM
Quote from: Kindred on February 09, 2025, 05:14:08 PMAlso,  clear your error log

Yup, did that:

delete from smf2009_log_errors;
alter table smf2009_log_errors auto_increment = 0;
Title: Re: Uncaught mysqli_sql_exception: Duplicate entry '16777215' for key 'PRIMARY' in /
Post by: Kindred on February 10, 2025, 12:41:05 PM
Or just use the admin interface to do it.

Doing direct database edits is almost never the right way
Title: Re: Uncaught mysqli_sql_exception: Duplicate entry '16777215' for key 'PRIMARY' in /
Post by: stray_tachyon on February 11, 2025, 12:53:42 AM
Sorry, one more question
Our current forum is on 2.0.18 http://www.china-defense.com/smf/index.php with database table prefix of "smf2009_"

I have installed 2.1.14 https://www.china-defense.com/smf214/index.php with database table prefix of "smf214_"

Is there a guide on how to migrate data from one forum installation to another?


Thank you very very much.
Title: Re: Uncaught mysqli_sql_exception: Duplicate entry '16777215' for key 'PRIMARY' in /
Post by: Oldiesmann on February 11, 2025, 01:11:02 AM
There is no migration involved. SMF supports directly upgrading from one version to another. See https://wiki.simplemachines.org/smf/Upgrading for more information.
Title: Re: Uncaught mysqli_sql_exception: Duplicate entry '16777215' for key 'PRIMARY' in /
Post by: Kindred on February 11, 2025, 08:19:42 AM
Also, putting two instances of smf in the same database is a bad idea,  even with different prefixes
Title: Re: Uncaught mysqli_sql_exception: Duplicate entry '16777215' for key 'PRIMARY' in /
Post by: stray_tachyon on February 11, 2025, 06:01:01 PM
Thanks.

Any idea why none of the pictures are showing when using SSL?

http://www.china-defense.com/smf/index.php

https://www.china-defense.com/smf/index.php
Title: Re: Uncaught mysqli_sql_exception: Duplicate entry '16777215' for key 'PRIMARY' in /
Post by: Kindred on February 11, 2025, 06:09:41 PM
Because you used http for the image url?
Title: Re: Uncaught mysqli_sql_exception: Duplicate entry '16777215' for key 'PRIMARY' in /
Post by: stray_tachyon on February 11, 2025, 09:08:35 PM
Quote from: Kindred on February 11, 2025, 06:09:41 PMBecause you used http for the image url?

Is it configured within the SMF or the hosting company?

Thanks.
Title: Re: Uncaught mysqli_sql_exception: Duplicate entry '16777215' for key 'PRIMARY' in /
Post by: Kindred on February 11, 2025, 09:18:24 PM
Whatever you set it to use in smf admin
Title: Re: Uncaught mysqli_sql_exception: Duplicate entry '16777215' for key 'PRIMARY' in /
Post by: stray_tachyon on February 11, 2025, 09:25:59 PM
Quote from: Kindred on February 11, 2025, 09:18:24 PMWhatever you set it to use in smf admin

Thanks.
Title: Re: Uncaught mysqli_sql_exception: Duplicate entry '16777215' for key 'PRIMARY' in /
Post by: stray_tachyon on February 12, 2025, 02:14:53 AM
Quote from: Kindred on February 11, 2025, 09:18:24 PMWhatever you set it to use in smf admin

Would you mind telling me where in the admin I can configure the image URL?

In the Settings.php of the live site, I have
$image_proxy_enabled = true;
$image_proxy_secret = '<some random string';
$image_proxy_maxsize = 5190;

For example I can load the image without SSL after I am logged in:
http://www.china-defense.com/smf/Themes/default/images/boardicons.png

but can't load it in SSL still
https://www.china-defense.com/smf/Themes/default/images/boardicons.png

Thanks
Title: Re: Uncaught mysqli_sql_exception: Duplicate entry '16777215' for key 'PRIMARY' in /
Post by: Kindred on February 12, 2025, 06:34:04 AM
Ok, that's a whole different issue...

the images not showing up when the theme is loaded is usually due to using the wrong URL for the setting
(header logo image, avatars, attachments, themes, etc)

Not being able to load it DIRECTLY via https suggests that you have a badly configured HOST!
Title: Re: Uncaught mysqli_sql_exception: Duplicate entry '16777215' for key 'PRIMARY' in /
Post by: stray_tachyon on February 13, 2025, 02:58:30 PM
Quote from: Kindred on February 12, 2025, 06:34:04 AMOk, that's a whole different issue...

the images not showing up when the theme is loaded is usually due to using the wrong URL for the setting
(header logo image, avatars, attachments, themes, etc)

Not being able to load it DIRECTLY via https suggests that you have a badly configured HOST!

You are absolutely right!!!

I commented out the following line in the .htaccess file and the icons are loaded in SSL
RewriteRule .*\.(jpg|jpeg|gif|png|bmp)$ - [F,NC]

Thanks again.