-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Bug: Model insert Created_at and updated_at get when new record added #2737
Comments
is anyone working on this issue? |
I'm unclear what the actual problem is. @Anmar-dev could you share some example code from your Model and the call to |
Sure thing @MGatner . Table structure.
` Model Code. `
` and finally controller code. ` ` for further details please refer to the app repository SurveyIgniter |
I got a similar issue, maybe the same, please find some details in regards to my findings: Problem description: Example:
} Entity class : use CodeIgniter\Entity; class UserEntity extends Entity
} Statement causing problems: ` try{
` The code above will work on the first call to the save() method without an id specified in the attributes array. In this case, created_at and populated_at will be populated in the database with the same value which appears to be correct. HOWEVER If you get the generated ID and call the same method again passing the ID, whenever it updates or save the object, the created_at and updated_at will be populated where the created_at apparently gets a timestamp from "Chicago" and the updated_at gets the server local timestamp. Hope it describes the problem. Amauri. |
This is not a problem with Codeigniter4 but a problem in the mysql table. In my case, I was using TIMESTAMP columns instead of DATETIME. By default MySQL does not allow null values in TIMESTAMP columns and will always assign a value to it automatically. To fix the problem I dropped the table and created it again with DATETIME columns. Amauri. |
Describe the bug
When i use model->save() to insert new record
when using Maria DB everything fine
When i use mySQL it seems the model add the timestamp for created_at and updated_at.
which is strange it could be only me.
CodeIgniter 4 version
Appstarter using composer 4.0.2
Affected module(s)
Model Class
Context
---------- an Update
MySQL version 5.7.26
The text was updated successfully, but these errors were encountered: