-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
[5.5] Fix SQL Server handling of DATETIME columns #22052
Conversation
Is this not a breaking change for 5.5? |
9ea0512
to
09fa73b
Compare
@taylorotwell Actually I was thinking it wasn't, but it was a breaking change for a different reason. Using This happens because To fix the whole issue we should be using The easier fix for 5.5 that I've found is changing I've added some basic tests that I believe are fulfilling both the expected and unexpected scenarios. 👍 Note that this solution shouldn't break anything, it's just a hack to allow retrieving and storing SQL Server's Now a technical explanation as to why currently it's hardcoded to When you store a timestamp like "2017-11-13 06:25:52" in a But there are some edge cases. Using the It would be sufficient using |
98a4dc7
to
14c67ce
Compare
14c67ce
to
c3425e0
Compare
Hi, I get this error when using Laravel 5.5.28 on my Ubuntu server. Any idea how to resolve this problem? |
FWIW, this was a breaking change for me. I get "Missing data" errors from Carbon saving an updated record. Currently reverting on my installs. |
Using The fractional seconds will jump from 999 to 1000 because of rounding errors, making it 4 digits, which mssql's Reference: |
That's not the problem, its every save and I'm running 7.2. |
Consider you're using this column in a migration:
Because SQL Server schema grammar is using the
DATETIME
column type for atimestamp()
column, the column will get a fixed precision of 3 fractional seconds which when used withDEFAULT CURRENT_TIMESTAMP
constraint would store values like "2017-11-13 06:25:52.150" that will fail to parse by Carbon if you declare this column on the model's$dates
property. 👍This is the SQL being generated for this column: http://sqlfiddle.com/#!6/16af5/1
This is the exception being thrown:
This is happening on
Iluminate\Database\Eloquent\Concerns\HasAttributes->asDateTime()
method at line 715 because$this->getDateFormat()
is receiving"Y-m-d H:i:s.000"
and"2017-11-13 06:25:52.150"
as arguments and this should fail: https://3v4l.org/Nu1p4I've found this with a fresh Laravel 5.5 install and SQL Server 2016 via Amazon RDS. The proposed change fixes the problem. It seems there's not tests for this yet, I'll try writing them later.