Problem with CURRENT_TIMESTAMP and editor

Problem with CURRENT_TIMESTAMP and editor

panzrampanzram Posts: 29Questions: 11Answers: 0
edited June 2019 in DataTables

Hi,

I have a site that's been running great for a while. Yesterday, our mysql database got migrated into a strict version. I've been able to locate and fix most issues, but one thing still remain and can't get my head around it.

The field that's given me grief is a timestamp with a default set to CURRENT_TIMESTAMP. When I insert a new record, by the use of the editor modal, I get this error:
SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: current_timestamp() for column created_at

The sql is:
The SQL statement executed was: INSERT INTO mytable (created_at, name) VALUES (:yp0, :yp1)

When I run the same sql (replacing the parameters :yp0 and :yp1 with values), it works brilliantly, so the error must either come from my client- or server-side scripts. I don't know how to debug and see what the :yp0 and :yp1 values are, would really like to take closer peek at those.

The related client-side script is:

{ data: "created_at" },

The related server-side script is:

Field::inst( created_at ), `
    /*`
    Field::inst( created_at )
        ->validator( Validate::dateFormat, array(
            "format"  => Format::DATE_ISO_8601,
            "message" => "Please enter a date in the format yyyy-mm-dd"
        ) )
        ->getFormatter( Format::date_sql_to_format, Format::DATE_ISO_8601 )
        ->setFormatter( Format::date_format_to_sql, Format::DATE_ISO_8601 ),
    */

I've tried both the rem:ed part and the other part, but nothing seems to work.

Any comments or ideas is greatly appreciated.

Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 12,939Questions: 0Answers: 2,204
    Answer ✓

    Hi @panzram ,

    A good way would be to look at the network tab in the developer's tool of the browser, and see what the Editor client is sending back to the client. Could you also post the client-side code for that field, please.

    Cheers,

    Colin

  • panzrampanzram Posts: 29Questions: 11Answers: 0

    Thx, Colin. I know about the network tab, but in this case I couldn't explore the data.

    I solved it now by going in another direction. If anyone is interested, I put the field default from CURRENT_TIMESTAMP to "0000-00-00 00:00:00" and set the date manually from my server-side instead. I still don't understand why it didn't work as it was.

  • jimomakjimomak Posts: 22Questions: 4Answers: 0

    error "An SQL error occurred: SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect integer value: '' for column users.vendors.Id at row 1

    This is a odd error, as the database does not have a column with a datetime format, nor do any of the php files in use. table.vendors.php does not have a datetime field, nor the html headers, nor table.vendors.js . I've rebooted, cleared the cache, checked the files, yet this error persists. I generated the first table 'users' which had a datatime field. I then copied theses files, changed the fields, generated the table properly, and it all renders. Everything works accept 'CREATE' which throws this error.
    Does anyone have an idea?

  • colincolin Posts: 12,939Questions: 0Answers: 2,204

    Thread repeated here - please only post once.

    Colin

  • allanallan Posts: 54,909Questions: 1Answers: 8,606 Site admin

    My guess is that you need to add .Set(false) to the Id field. However, without the full code, it is difficult to know for sure. Perhaps you can show the code you are using please?

    Allan

Sign In or Register to comment.