Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Posting data to a new input fails with sql error. #1873

Closed
andyjbm opened this issue Mar 22, 2024 · 3 comments
Closed

Posting data to a new input fails with sql error. #1873

andyjbm opened this issue Mar 22, 2024 · 3 comments

Comments

@andyjbm
Copy link

andyjbm commented Mar 22, 2024

When posting some data today emoncms (Version [11.4.6]) that was going to create a new input I was getting an error:

EMONCMS Result: 200, <br /> <b>Fatal error</b>: Uncaught mysqli_sql_exception: Field 'record' doesn't have a default value in /var/www/html/emoncms/Modules/input/input_model.php:41 Stack trace: #0 /var/www/html/emoncms/Modules/input/input_model.php(41): mysqli_stmt-&gt;execute() #1 /var/www/html/emoncms/Modules/input/input_methods.php(328): Input-&gt;create_input(10, '99', 'C1') #2 /var/www/html/emoncms/Modules/input/input_methods.php(182): InputMethods-&gt;process_node('10', 1711131893, '99', Array) #3 /var/www/html/emoncms/Modules/input/input_controller.php(54): InputMethods-&gt;post('10') #4 /var/www/html/emoncms/core.php(74): input_controller() #5 /var/www/html/emoncms/index.php(242): controller('input') #6 {main} thrown in <b>/var/www/html/emoncms/Modules/input/input_model.php</b> on line <b>41</b><br />

So the sql line 39 of input_model.php is failing:
if ($stmt = $this->mysqli->prepare("INSERT INTO input (userid,name,nodeid,description,processList) VALUES (?,?,?,'','')")) {
because the table "Input" field "record" doesn't have a default value, it doesn't allow nulls and the INSERT is not explicitly posting one.

Not sure how I got here - meaning which upgrade broke it - but it's been a while since I've tried to create new inputs.

I looked at the existing records in the input table and they all have a value of 0 for field record so I'm adding that as a default which should fix it.

I'm opening this issue as a heads up that maybe something that used to use record doesn't anymore in an upgrade but I have a db with old schema and maybe "record" is an obsolete field?

Thanks,

Andy.

@andyjbm
Copy link
Author

andyjbm commented Mar 22, 2024

PS:

Yes that fixed it:
ALTER TABLE input ALTER record SET default 0;

As soon as that was done the data posting returned with no errors and my new inputs were populated on the input/view page.

Like I hinted earlier, this may not be an issue for a fresh BNIB install of emoncms. It may be because I've had the db for years and updated emoncms along the way & somewhere field record was depreciated. There may be others out there with the issue hiding covertly on their db too.

If that's the case it would be good to know and I can go ahead and drop it altogether.

Thanks,
Andy.

@TrystanLea
Copy link
Member

Hello @andyjbm yes you can delete the field record, it is no longer used.

@andyjbm
Copy link
Author

andyjbm commented Apr 30, 2024

Hello @andyjbm yes you can delete the field record, it is no longer used.

Hi @TrystanLea, Thanks for the info. Will do that.

Andy.

@andyjbm andyjbm closed this as completed Apr 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants