Advertisement:

Author Topic: Field 'id_reporter' doesn't have a default value  (Read 1163 times)

Offline videoed

  • Jr. Member
  • **
  • Posts: 174
  • Gender: Male
  • Ramón Cutanda
    • videoedicion.org
Field 'id_reporter' doesn't have a default value
« on: March 21, 2019, 05:51:06 PM »
I have recently upgraded from 2.0.15 to 2.1 RC1. The report funcion doesn't work. I get this error:
Code: [Select]
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...


Code: [Select]
    // 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!

Offline Sir Osis of Liver

  • SMF Hero
  • ******
  • Posts: 9,300
Re: Field 'id_reporter' doesn't have a default value
« Reply #1 on: March 21, 2019, 11:34:35 PM »
It's a mysql bug.  Assign a default value of "Null" to the field, that should fix it.

Offline albertlast

  • Development Contributor
  • Full Member
  • *
  • Posts: 589
Re: Field 'id_reporter' doesn't have a default value
« Reply #2 on: March 22, 2019, 12:04:56 AM »
Look like a real bug,
So  don't do the null thing,
What sir osis  says.

Offline Sir Osis of Liver

  • SMF Hero
  • ******
  • Posts: 9,300
Re: Field 'id_reporter' doesn't have a default value
« Reply #3 on: March 22, 2019, 12:21:05 AM »
Is that '1' a stray character?

Offline albertlast

  • Development Contributor
  • Full Member
  • *
  • Posts: 589
Re: Field 'id_reporter' doesn't have a default value
« Reply #4 on: March 22, 2019, 12:26:19 AM »
this is the new way in 2.1 to get the ai value from ai field while inserting:
https://github.com/SimpleMachines/SMF2.1/blob/release-2.1/Sources/Subs-Db-mysql.php#L725

Offline albertlast

  • Development Contributor
  • Full Member
  • *
  • Posts: 589
Re: Field 'id_reporter' doesn't have a default value
« Reply #5 on: March 22, 2019, 12:31:24 AM »
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.

Offline videoed

  • Jr. Member
  • **
  • Posts: 174
  • Gender: Male
  • Ramón Cutanda
    • videoedicion.org
Re: Field 'id_reporter' doesn't have a default value
« Reply #6 on: March 22, 2019, 02:33:45 AM »
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!

Offline videoed

  • Jr. Member
  • **
  • Posts: 174
  • Gender: Male
  • Ramón Cutanda
    • videoedicion.org
Re: Field 'id_reporter' doesn't have a default value
« Reply #7 on: March 28, 2019, 11:07:11 AM »
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,

Offline albertlast

  • Development Contributor
  • Full Member
  • *
  • Posts: 589
Re: Field 'id_reporter' doesn't have a default value
« Reply #8 on: March 28, 2019, 01:20:03 PM »
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.

Offline Sir Osis of Liver

  • SMF Hero
  • ******
  • Posts: 9,300
Re: Field 'id_reporter' doesn't have a default value
« Reply #9 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.

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 71,630
    • StoryBB/StoryBB on GitHub
Re: Field 'id_reporter' doesn't have a default value
« Reply #10 on: March 28, 2019, 04:57:24 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.
Don’t try to tell me that some power can corrupt a person. You haven’t had enough to know what it’s like.

No good deed goes unpunished / No act of charity goes unresented.

Offline Sir Osis of Liver

  • SMF Hero
  • ******
  • Posts: 9,300
Re: Field 'id_reporter' doesn't have a default value
« Reply #11 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?

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 71,630
    • StoryBB/StoryBB on GitHub
Re: Field 'id_reporter' doesn't have a default value
« Reply #12 on: March 28, 2019, 05:16:56 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.
Don’t try to tell me that some power can corrupt a person. You haven’t had enough to know what it’s like.

No good deed goes unpunished / No act of charity goes unresented.

Offline Sir Osis of Liver

  • SMF Hero
  • ******
  • Posts: 9,300
Re: Field 'id_reporter' doesn't have a default value
« Reply #13 on: March 28, 2019, 05:23:21 PM »
That's been the recommended fix here for some time, and afaik it's worked in all instances.

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 71,630
    • StoryBB/StoryBB on GitHub
Re: Field 'id_reporter' doesn't have a default value
« Reply #14 on: March 28, 2019, 05:44:01 PM »
Yes, except for when the column is autoincrement like this one is.
Don’t try to tell me that some power can corrupt a person. You haven’t had enough to know what it’s like.

No good deed goes unpunished / No act of charity goes unresented.

Offline Sir Osis of Liver

  • SMF Hero
  • ******
  • Posts: 9,300
Re: Field 'id_reporter' doesn't have a default value
« Reply #15 on: March 28, 2019, 05:49:47 PM »
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.

Offline albertlast

  • Development Contributor
  • Full Member
  • *
  • Posts: 589
Re: Field 'id_reporter' doesn't have a default value
« Reply #16 on: March 28, 2019, 06:01:44 PM »
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.

Offline Sir Osis of Liver

  • SMF Hero
  • ******
  • Posts: 9,300
Re: Field 'id_reporter' doesn't have a default value
« Reply #17 on: March 28, 2019, 06:05:18 PM »
Well, apparently it worked for OP.  Will it break something else?

Offline videoed

  • Jr. Member
  • **
  • Posts: 174
  • Gender: Male
  • Ramón Cutanda
    • videoedicion.org
Re: Field 'id_reporter' doesn't have a default value
« Reply #18 on: March 28, 2019, 06:06:33 PM »
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:

Code: [Select]
#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,

Offline Sir Osis of Liver

  • SMF Hero
  • ******
  • Posts: 9,300
Re: Field 'id_reporter' doesn't have a default value
« Reply #19 on: March 28, 2019, 06:14:40 PM »
Sadly, I don't have id_reporter field in smf_log_reported. :(