MyBB Community Forums

Full Version: MySQL field doesn't have a default value
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
When trying to create a new thread, I get this error:


Quote:MyBB has experienced an internal SQL error and cannot continue.

SQL Error:
1364 - Field 'pid' doesn't have a default value
Query:
INSERT INTO mybb_spamalyser_log (event,score,details,dateline,message,uid,username,fid,ipaddress,httpreq,timeonline,postcount,actions,subject)

This only happens for normal registered users and guest users with no account. This error does not happen for admins or moderators

Obviously its related to the "Spamalyzer" plugin that I use

However, I don't believe this issue is related to mybb, because another mysql db on my website was also giving me this error recently. Perhaps my webhost has upgraded to a new mysql version that changes how db columns work regarding default values. How i fixed it in my other db, was simply to make sure that I'm always passing the value into the mysql insert statement. Previously the value was omitted, and so i guess mysql was trying to use a default value.

Here is a link to the plugin:

https://github.com/mmikeww/mybb-spamalyser

Can anyone with some deeper knowledge help me out?
What lines need to be edited so that I can explicitly pass the pid instead of relying on default values?
or
How can I update the DB schema so that the 'pid' column has a default/empty value if it was omitted in the insert statement?
Edit the line 169 of /inc/plugins/spamalyser/sp_admin.php

Original: pid int(11) unsigned not null,

New: Original: pid int(11) unsigned not null DEFAULT 0,
(2022-07-07, 02:01 PM)mikew Wrote: [ -> ]How can I update the DB schema so that the 'pid' column has a default/empty value if it was omitted in the insert statement?

I fixed it using this:

ALTER TABLE `mybb_spamalyser_log` CHANGE `pid` `pid` int(11) unsigned NOT NULL DEFAULT '0' AFTER `lid`;

(2022-07-07, 02:25 PM)Crazycat Wrote: [ -> ]Edit the line 169 of /inc/plugins/spamalyser/sp_admin.php

Original:  pid int(11) unsigned not null,

New: Original:  pid int(11) unsigned not null DEFAULT 0,


Thanks. This would only work on initial db creation correct? And my ALTER statement above would work on existing dbs?
Exactly!
You can run an ALTER TABLE statement at any time.
So you did, the change has been made to the running database.

Also change the line in the *.php file just for the case you ever uninstall the plugin and re-install it - else the table will be created again with missing default value.

[ExiTuS]