Field 'id_reporter' doesn't have a default value

Started by Ramón Cutanda, March 21, 2019, 05:51:06 PM

Previous topic - Next topic

Ramón Cutanda

I have recently upgraded from 2.0.15 to 2.1 RC1. The report funcion doesn't work. I get this error:
Field 'id_reporter' doesn't have a default value
File: /var/www/vhosts/videoedicion.org/httpdocs/foro/Sources/ReportToMod.php
Line: 303

In my ReportToMod.php line 303 is the number "1" almost at the end of this function. So no clues for me...


    // Otherwise, we shall make one!
    else
    {
        if (empty($message['real_name']))
            $message['real_name'] = $message['poster_name'];

        $id_report = $smcFunc['db_insert']('',
            '{db_prefix}log_reported',
            array(
                'id_msg' => 'int', 'id_topic' => 'int', 'id_board' => 'int', 'id_member' => 'int', 'membername' => 'string',
                'subject' => 'string', 'body' => 'string', 'time_started' => 'int', 'time_updated' => 'int',
                'num_reports' => 'int', 'closed' => 'int',
            ),
            array(
                $_POST['msg'], $message['id_topic'], $message['id_board'], $message['id_poster'], $message['real_name'],
                $message['subject'], $message['body'], time(), time(), 1, 0,
            ),
            array('id_report'),
            1
        );
    }



Any help with this?

Thanks!

Sir Osis of Liver

It's a mysql bug.  Assign a default value of "Null" to the field, that should fix it.
Ashes and diamonds, foe and friend,
 we were all equal in the end.

                                     - R. Waters

albertlast

Look like a real bug,
So  don't do the null thing,
What sir osis  says.

Sir Osis of Liver

Ashes and diamonds, foe and friend,
 we were all equal in the end.

                                     - R. Waters

albertlast


albertlast

Well i checked the code for upgrade,
ther it's look fine.

So it look like the problem only exists on your side,
you can fixit by altering the id_report to auto_increment field.

Ramón Cutanda

My table already had the auto_increment value so, considering that table was empty, I dropped it and recreated it using the template from the install_2-1_mysql.sql file included in the full install package. That solved the problem :-)

Thanks for the help!

Ramón Cutanda

The report worked in my testings, but it broke again. Because the error message complains of not having a "default" value, I added a NULL default value in the table. Now I have tried with more than a dozen reports and everything seems to be working normally.

Thanks,

albertlast

Well this make no sense,
since it's pk with ai,
the error should not happen.

Would be better when you show us your table structur instead of doing wrong things.

Sir Osis of Liver

Does 2.1 code address the mysql bug?  This has been a recurring problem in 2.0.
Ashes and diamonds, foe and friend,
 we were all equal in the end.

                                     - R. Waters

Arantor

Quote from: Sir Osis of Liver on March 28, 2019, 04:53:19 PM
Does 2.1 code address the mysql bug?  This has been a recurring problem in 2.0.


It's not a bug, it's MySQL finally working to spec.

And no, 2.1 doesn't address it, it forces the same behaviour on everyone, including people who previously avoided it. Maybe mod authors will get their **** together and do it properly from the start this time.

Sir Osis of Liver

So then, adding 'Null' to the field to fix the problem is not 'doing wrong things', is it?
Ashes and diamonds, foe and friend,
 we were all equal in the end.

                                     - R. Waters

Arantor

Quote from: Sir Osis of Liver on March 28, 2019, 05:11:20 PM
So then, adding 'Null' to the field to fix the problem is not 'doing wrong things', is it?


To a column that is explicitly designed to not receive values from the user and to generate them on demand would appear to be the wrong thing.

Sir Osis of Liver

That's been the recommended fix here for some time, and afaik it's worked in all instances.
Ashes and diamonds, foe and friend,
 we were all equal in the end.

                                     - R. Waters

Arantor

Yes, except for when the column is autoincrement like this one is.

Sir Osis of Liver

What effect does it have?  If field starts out with no value, or 'null' value, won't it still auto increment to '1' on first use?  After that it would no longer matter.
Ashes and diamonds, foe and friend,
 we were all equal in the end.

                                     - R. Waters

albertlast

Very important point what this here make differently to all other similiar issues,
this is here a smf field, exists since 2.0.x,
so it's not a mod field.

Secondly this field in this table is pk,
pk are not allowed to be null -> this fields can't be null able, when everything is setup in the right way.

Third in the 2.0 and 2.1 setup is this field defined as pk with ai,
so this issue shouldn't exists.

Sir Osis of Liver

Well, apparently it worked for OP.  Will it break something else?
Ashes and diamonds, foe and friend,
 we were all equal in the end.

                                     - R. Waters

Ramón Cutanda

I am not a coder or a developer. I have a VERY limited understanding of PHP or MySQL and you can take for granted that I don't really know what I am doing.

I tried to set the field as auto_increment, as suggested. But I get this error:

#1075 - Incorrect table definition; there can be only one auto column and it must be defined as key

Then I just followed the "instructions" of the error message. If the system complaints about not having a "default" value... well.. I just tried that. To set a default value. As a "non-coder" user that made perfect sense to me. And the thing is that it works... Why? I have NO IDEA; but it works and I just wanted to share.

If you have any other suggestion to make my reports work or give me a reason not to set NULL as the default value (security risk, possible data corruption...) then sure I will follow your advice.

Thank you for all your contributions and interest in this matter.

Bests,

Sir Osis of Liver

Sadly, I don't have id_reporter field in smf_log_reported. :(
Ashes and diamonds, foe and friend,
 we were all equal in the end.

                                     - R. Waters

Advertisement: