我正在Django写一个小脚本。它基于Command类供cron执行。我正在使用pyodbc和MS-SQL。
class Command(BaseCommand):
help = 'Sends email notifications'
def handle(self, *args, **options):
all_open_port = MyEmailModel.objects.using('emaildb').filter(u_sentinstant__gte=datetime.date.today())
for p in all_open_port:
self.stdout.write(p.u_sentinstant)
self.stdout.write(self.style.SUCCESS('Successfully finished.'))
在评估QuerySet时,我得到了这个错误:
AttributeError:'Query'对象没有属性'aggregate_select'
我无法解决此问题,因为代码与文档相同......
回溯:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\user\AppData\Local\Programs\Python\Python35\lib\site-packages\django\core\management\__init__.py", line 367, in execute_from_command_line
utility.execute()
File "C:\Users\user\AppData\Local\Programs\Python\Python35\lib\site-packages\django\core\management\__init__.py", line 359, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\user\AppData\Local\Programs\Python\Python35\lib\site-packages\django\core\management\base.py", line 294, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\user\AppData\Local\Programs\Python\Python35\lib\site-packages\django\core\management\base.py", line 345, in execute
output = self.handle(*args, **options)
File "C:\Users\user\Desktop\CarrierExchange\cusnotifier\management\commands\sendnotifications.py", line 12, in handle
for p in all_open_port:
File "C:\Users\user\AppData\Local\Programs\Python\Python35\lib\site-packages\django\db\models\query.py", line 256, in __iter__
self._fetch_all()
File "C:\Users\user\AppData\Local\Programs\Python\Python35\lib\site-packages\django\db\models\query.py", line 1087, in _fetch_all
self._result_cache = list(self.iterator())
File "C:\Users\user\AppData\Local\Programs\Python\Python35\lib\site-packages\django\db\models\query.py", line 54, in __iter__
results = compiler.execute_sql()
File "C:\Users\user\AppData\Local\Programs\Python\Python35\lib\site-packages\django\db\models\sql\compiler.py", line 824, in execute_sql
sql, params = self.as_sql()
File "C:\Users\user\AppData\Local\Programs\Python\Python35\lib\site-packages\django_pyodbc\compiler.py", line 204, in as_sql
self._fix_aggregates()
File "C:\Users\user\AppData\Local\Programs\Python\Python35\lib\site-packages\django_pyodbc\compiler.py", line 180, in _fix_aggregates
for alias, aggregate in self.query.aggregate_select.items():
AttributeError: 'Query' object has no attribute 'aggregate_select'
答案 0 :(得分:1)
似乎是最新的pyodbc / django-pyodbc中的一个错误: https://github.com/lionheart/django-pyodbc/pull/146/files
用“lib \ site-packages \ django_pyodbc \ compiler.py”中的“annotation_select”替换“aggregate_select”可以解决问题。