1
回溯講述的故事:Django的.save()不可預知的處理update_fields輸入
Error
Traceback (most recent call last):
File "/Users/adamstarrh/almondking/AlmondKing/tests/test_models/test_financial_logs.py", line 35, in test_cogs_per_tag
self.assertEqual(self.sale5.cogs_per_tag, {10: 1813365, 3: 5623801, 4: 4140737})
File "/Users/adamstarrh/almondking/AlmondKing/FinancialLogs/models.py", line 244, in cogs_per_tag
cogs[tag[0]] = float(round(shipment.adjusted_cost * tag[1]))
File "/Users/adamstarrh/almondking/AlmondKing/InventoryLogs/models.py", line 509, in adjusted_cost
return self.cost_inr_per_kg
File "/Users/adamstarrh/almondking/AlmondKing/InventoryLogs/models.py", line 499, in cost_inr_per_kg
Decimal(self.reverse_exchange_rate), 4)
File "/Users/adamstarrh/almondking/AlmondKing/InventoryLogs/models.py", line 477, in reverse_exchange_rate
self.save(update_fields="rate_usd_inr")
File "/Users/adamstarrh/almondking/AlmondKing/lib/python3.5/site-packages/django/db/models/base.py", line 714, in save
% ', '.join(non_model_fields))
ValueError: The following fields do not exist in this model or are m2m fields: u, _, n, a, r, s, e, t, i, d
當我嘗試調用self.save(update_fields="rate_usd_inr")
,而不是更新的字符串中提供的字段,它看起來與每個個性領域在字符串中。
這對我來說一直工作好幾個月。我很確定我昨天停止工作時成功地運行了測試。我在編寫代碼時肯定沒有遇到過。當我今天早上再次跑過它時,它纔開始出現。
謝謝!顯然它畢竟還沒有爲我工作。 o.o –
@AdamStarrh發生,有時我會發現代碼庫中的古代事物,甚至無法工作:) – alecxe