简体   繁体   English

使用 laravel eloquent 创建数据库记录时出现查询异常

[英]Query Exception when creating a database record using laravel eloquent

I am encountering a weird error.我遇到了一个奇怪的错误。 In a laravel project I am reading a CSV file.在 laravel 项目中,我正在阅读 CSV 文件。 In my Controller I am parsing the CSV and creating database records for a mysql database .在我的Controller 中,我正在解析 CSV并为mysql 数据库创建数据库记录。 I convert the CSV lines into individual arrays which are located within a big array -> two dimensional array.我将 CSV 线转换为单独的 arrays ,它们位于一个大数组 -> 二维数组中。 So far so good.到目前为止,一切都很好。 When iterating through my array the first iteration works just fine and I get the database records as expected.当迭代我的数组时,第一次迭代工作得很好,我得到了预期的数据库记录。 However, during the second iteration a Query Exception is thrown.但是,在第二次迭代期间会引发查询异常。 The stack trace leads me to a line where I am assigning a double value to an attribute of the model.堆栈跟踪将我引导到我为 model 的属性分配双精度值的行。

          Transaction::firstOrCreate([
            'date' => $date,
            'transaction_type' => $the_big_array[$i][2],
            'db_counter_party_id' => $db_counter_party_id,
            'amount' => $amount,
            'currency' => $the_big_array[$i][6],
            'usage' => $the_big_array[$i][7],
            'category' => "none",
            'balance' => $balance_after_transaction,
          ]);

The last assignment is causing the error.最后一个分配导致错误。 The variable balance_after_transaction is of type double and calculated according to previous transactions.变量balance_after_transaction是 double 类型,根据之前的交易计算。 So it is not directly retrieved from the CSV.所以它不是直接从 CSV 中检索出来的。 Does someone have a clue what is going on?有人知道发生了什么吗?

The error was caused by a wrong character encoding.该错误是由错误的字符编码引起的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM