fopina / django-bulk-update-or-create

`bulk_update_or_create` for Django model managers
MIT License
148 stars 16 forks source link

Mutiple fields not working #32

Closed shakthifuture closed 2 years ago

shakthifuture commented 2 years ago

the below code throw the error of django.db.utils.Error: ('07002', '[07002] [Microsoft][ODBC Driver 17 for SQL Server]COUNT field incorrect or syntax error (0) (SQLExecDirectW)')

MasterOutput.objects.bulk_update_or_create(recalc_masterdata, ['final_core_demand_mins', 'input_thirdparty_supply_mins'], match_field='masteroutput_id')

But the same code works for a single field updates.

MasterOutput.objects.bulk_update_or_create(recalc_masterdata, ['input_thirdparty_supply_mins'], match_field='masteroutput_id') MasterOutput.objects.bulk_update_or_create(recalc_masterdata, ['final_core_demand_mins'], match_field='masteroutput_id')

What could be wrong here?

fopina commented 2 years ago

I’ve never used sql server so I honestly have no idea. Please post the full stacktrace of the exception

shakthifuture commented 2 years ago

Here is the full stack trace @fopina.

Traceback (most recent call last): *_File "D:\Checkout\RAC_tool-raw\rac-django\backend\masteroutput\viewsets.py", line 324, in modify_masterdata MasterOutput.objects.bulk_update(recalc_masterdata, ['final_core_demand_mins','input_thirdparty_supply_mins']) File "D:\Checkout\Environments\venv47\lib\site-packages\django\db\models\manager.py", line 85, in manager_method return getattr(self.get_queryset(), name)(args, kwargs) File "D:\Checkout\Environments\venv47\lib\site-packages\mssql\functions.py", line 270, in bulk_update_with_default self.filter(pk__in=pks).update(update_kwargs) File "D:\Checkout\Environments\venv47\lib\site-packages\django\db\models\query.py", line 783, in update rows = query.get_compiler(self.db).execute_sql(CURSOR) File "D:\Checkout\Environments\venv47\lib\site-packages\django\db\models\sql\compiler.py", line 1559, in execute_sql cursor = super().execute_sql(result_type) File "D:\Checkout\Environments\venv47\lib\site-packages\django\db\models\sql\compiler.py", line 1175, in execute_sql cursor.execute(sql, params) File "D:\Checkout\Environments\venv47\lib\site-packages\django\db\backends\utils.py", line 66, in execute return self._execute_with_wrappers(sql, params, many=False, executor=self._execute) File "D:\Checkout\Environments\venv47\lib\site-packages\django\db\backends\utils.py", line 75, in _execute_with_wrappers return executor(sql, params, many, context) File "D:\Checkout\Environments\venv47\lib\site-packages\django\db\backends\utils.py", line 84, in _execute return self.cursor.execute(sql, params) File "D:\Checkout\Environments\venv47\lib\site-packages\django\db\utils.py", line 90, in exit raise dj_exc_value.with_traceback(traceback) from exc_value File "D:\Checkout\Environments\venv47\lib\site-packages\django\db\backends\utils.py", line 84, in execute return self.cursor.execute(sql, params) File "D:\Checkout\Environments\venv47\lib\site-packages\mssql\base.py", line 595, in execute return self.cursor.execute(sql, params) django.db.utils.Error: ('07002', '[07002] [Microsoft][ODBC Driver 17 for SQL Server]COUNT field incorrect or syntax error (0) (SQLExecDirectW)')**

fopina commented 2 years ago

just noticed you’re using “bulk_update”.

that’s core django, you’re not using this package.