You have changed an existing migration or you added a new one? Which trait are you using in your tests for the Database?
Do you maybe cast or have a mutator in your Admin model for the status field?
Summer Sale! All accounts are 50% off this week.
Hy folks , at first, I was having that test :
$this->admin->update([
'first_name' => 'updated-first_name',
'status' => 'approved'
]);
$this->assertEquals($this->admin->refresh()->getAttributes()->toArray(),[
'first_name' => 'updated-first_name',
'status' => 'approved',
])
at this point, everything is going right. but after I decide to change the status to be an integer I have changed the migration like the following :
$table->unsignedInteger('status')->default(0);
I was expecting that the test will fail but it's still passed !! to make sure I die and dumped the user after the updated process and I got its status updated to string !!! it should throw a database exception or I am missing something here !!
Oh got it.
This is a frequently asked question—it's literally in SQLite's FAQ: (3) SQLite lets me insert a string into a database column of type integer! This is a feature, not a bug. SQLite uses dynamic typing. It does not enforce data type constraints. Any data >can be inserted into any column. You can put arbitrary length strings into integer columns, floating point >numbers in boolean columns, or dates in character columns. The datatype you assign to a column in the >CREATE TABLE command does not restrict what data can be put into that column. Every column is able to hold >an arbitrary length string. (There is one exception: Columns of type INTEGER PRIMARY KEY may only hold a 64->bit signed integer. An error will result if you try to put anything other than an integer into an INTEGER PRIMARY >KEY column.)
But SQLite does use the declared type of a column as a hint that you prefer values in that format. So, for >example, if a column is of type INTEGER and you try to insert a string into that column, SQLite will attempt to >convert the string into an integer. If it can, it inserts the integer instead. If not, it inserts the string. This feature is >called type affinity. It was sqlit feature not a laravel or sqlit bug . https://stackoverflow.com/questions/10772028/boolean-datatype-accepting-string-value-and-integer-value
Please or to participate in this conversation.