Please use triple ` around your code :) https://help.github.com/en/articles/creating-and-highlighting-code-blocks
Illuminate\Database\QueryException in Laravel 6.0
I am having a problem with Laravel 6.0. The same source code is running ok with Laravel 5.8. The error is the following:
Illuminate\Database\QueryException SQLSTATE[22018]: [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]Conversion failed when converting the nvarchar value 'XXXX' to data type int. (SQL: select * from [business_units] where [business_units].[code] in (0, 0, 0, 0))
Here is the migration:
Schema::create('cost_centers', function (Blueprint $table) {
$table->string('code', 6)->primary();
$table->string('descr', 50);
$table->string('business_unit_code', 6)->index();
$table->foreign('business_unit_code')->references('code')->on('business_units');
$table->timestamps();
});
My Model script is:
class CostCenter extends Model
{
protected $primaryKey = 'code';
protected $fillable = ['code', 'descr', 'business_unit_code'];
public $incrementing = false;
public function businessUnit()
{
return $this->belongsTo(BusinessUnit::class);
}
}
This is after opening a form with the column in the table referencing another column where primary key is String. Did anybody encounter this problem, what is your resolution?
Please or to participate in this conversation.