[2020-04-06 20:53:11,587: INFO/MainProcess] Writing entries...
[2020-04-06 20:53:11,588: WARNING/MainProcess] Traceback (most recent call last):
[2020-04-06 20:53:11,588: WARNING/MainProcess] File "/Users/zpf/.virtualenvs/jjhzk/bin/celery", line 10, in
[2020-04-06 20:53:11,588: WARNING/MainProcess] sys.exit(main())
[2020-04-06 20:53:11,588: WARNING/MainProcess] File "/Users/zpf/.virtualenvs/jjhzk/lib/python3.6/site-packages/celery/__main__.py", line 16, in main
[2020-04-06 20:53:11,588: WARNING/MainProcess] _main()
[2020-04-06 20:53:11,588: WARNING/MainProcess] File "/Users/zpf/.virtualenvs/jjhzk/lib/python3.6/site-packages/celery/bin/celery.py", line 322, in main
[2020-04-06 20:53:11,589: WARNING/MainProcess] cmd.execute_from_commandline(argv)
[2020-04-06 20:53:11,589: WARNING/MainProcess] File "/Users/zpf/.virtualenvs/jjhzk/lib/python3.6/site-packages/celery/bin/celery.py", line 495, in execute_from_commandline
[2020-04-06 20:53:11,589: WARNING/MainProcess] super(CeleryCommand, self).execute_from_commandline(argv)))
[2020-04-06 20:53:11,589: WARNING/MainProcess] File "/Users/zpf/.virtualenvs/jjhzk/lib/python3.6/site-packages/celery/bin/base.py", line 305, in execute_from_commandline
[2020-04-06 20:53:11,590: WARNING/MainProcess] return self.handle_argv(self.prog_name, argv[1:])
[2020-04-06 20:53:11,590: WARNING/MainProcess] File "/Users/zpf/.virtualenvs/jjhzk/lib/python3.6/site-packages/celery/bin/celery.py", line 487, in handle_argv
[2020-04-06 20:53:11,590: WARNING/MainProcess] return self.execute(command, argv)
[2020-04-06 20:53:11,590: WARNING/MainProcess] File "/Users/zpf/.virtualenvs/jjhzk/lib/python3.6/site-packages/celery/bin/celery.py", line 419, in execute
[2020-04-06 20:53:11,590: WARNING/MainProcess] ).run_from_argv(self.prog_name, argv[1:], command=argv[0])
[2020-04-06 20:53:11,591: WARNING/MainProcess] File "/Users/zpf/.virtualenvs/jjhzk/lib/python3.6/site-packages/celery/bin/base.py", line 309, in run_from_argv
[2020-04-06 20:53:11,591: WARNING/MainProcess] sys.argv if argv is None else argv, command)
[2020-04-06 20:53:11,591: WARNING/MainProcess] File "/Users/zpf/.virtualenvs/jjhzk/lib/python3.6/site-packages/celery/bin/base.py", line 393, in handle_argv
[2020-04-06 20:53:11,591: WARNING/MainProcess] return self(*args, **options)
[2020-04-06 20:53:11,591: WARNING/MainProcess] File "/Users/zpf/.virtualenvs/jjhzk/lib/python3.6/site-packages/celery/bin/base.py", line 253, in __call__
[2020-04-06 20:53:11,591: WARNING/MainProcess] ret = self.run(*args, **kwargs)
[2020-04-06 20:53:11,592: WARNING/MainProcess] File "/Users/zpf/.virtualenvs/jjhzk/lib/python3.6/site-packages/celery/bin/beat.py", line 109, in run
[2020-04-06 20:53:11,592: WARNING/MainProcess] return beat().run()
[2020-04-06 20:53:11,592: WARNING/MainProcess] File "/Users/zpf/.virtualenvs/jjhzk/lib/python3.6/site-packages/celery/apps/beat.py", line 81, in run
[2020-04-06 20:53:11,592: WARNING/MainProcess] self.start_scheduler()
[2020-04-06 20:53:11,592: WARNING/MainProcess] File "/Users/zpf/.virtualenvs/jjhzk/lib/python3.6/site-packages/celery/apps/beat.py", line 109, in start_scheduler
[2020-04-06 20:53:11,592: WARNING/MainProcess] service.start()
[2020-04-06 20:53:11,592: WARNING/MainProcess] File "/Users/zpf/.virtualenvs/jjhzk/lib/python3.6/site-packages/celery/beat.py", line 637, in start
[2020-04-06 20:53:11,593: WARNING/MainProcess] self.scheduler._do_sync()
[2020-04-06 20:53:11,593: WARNING/MainProcess] File "/Users/zpf/.virtualenvs/jjhzk/lib/python3.6/site-packages/celery/beat.py", line 416, in _do_sync
[2020-04-06 20:53:11,594: WARNING/MainProcess] self.sync()
[2020-04-06 20:53:11,594: WARNING/MainProcess] File "/Users/zpf/.virtualenvs/jjhzk/lib/python3.6/site-packages/django_celery_beat/schedulers.py", line 302, in sync
[2020-04-06 20:53:11,595: WARNING/MainProcess] self.schedule[name].save()
[2020-04-06 20:53:11,595: WARNING/MainProcess] File "/Users/zpf/.virtualenvs/jjhzk/lib/python3.6/site-packages/django_celery_beat/schedulers.py", line 166, in save
[2020-04-06 20:53:11,596: WARNING/MainProcess] obj.save()
[2020-04-06 20:53:11,596: WARNING/MainProcess] File "/Users/zpf/.virtualenvs/jjhzk/lib/python3.6/site-packages/django_celery_beat/models.py", line 567, in save
[2020-04-06 20:53:11,596: WARNING/MainProcess] super(PeriodicTask, self).save(*args, **kwargs)
[2020-04-06 20:53:11,596: WARNING/MainProcess] File "/Users/zpf/.virtualenvs/jjhzk/lib/python3.6/site-packages/django/db/models/base.py", line 741, in save
[2020-04-06 20:53:11,597: WARNING/MainProcess] force_update=force_update, update_fields=update_fields)
[2020-04-06 20:53:11,597: WARNING/MainProcess] File "/Users/zpf/.virtualenvs/jjhzk/lib/python3.6/site-packages/django/db/models/base.py", line 779, in save_base
[2020-04-06 20:53:11,597: WARNING/MainProcess] force_update, using, update_fields,
[2020-04-06 20:53:11,597: WARNING/MainProcess] File "/Users/zpf/.virtualenvs/jjhzk/lib/python3.6/site-packages/django/db/models/base.py", line 851, in _save_table
[2020-04-06 20:53:11,598: WARNING/MainProcess] forced_update)
[2020-04-06 20:53:11,598: WARNING/MainProcess] File "/Users/zpf/.virtualenvs/jjhzk/lib/python3.6/site-packages/django/db/models/base.py", line 900, in _do_update
[2020-04-06 20:53:11,598: WARNING/MainProcess] return filtered._update(values) > 0
[2020-04-06 20:53:11,598: WARNING/MainProcess] File "/Users/zpf/.virtualenvs/jjhzk/lib/python3.6/site-packages/django/db/models/query.py", line 760, in _update
[2020-04-06 20:53:11,599: WARNING/MainProcess] return query.get_compiler(self.db).execute_sql(CURSOR)
[2020-04-06 20:53:11,599: WARNING/MainProcess] File "/Users/zpf/.virtualenvs/jjhzk/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 1429, in execute_sql
[2020-04-06 20:53:11,599: WARNING/MainProcess] cursor = super().execute_sql(result_type)
[2020-04-06 20:53:11,600: WARNING/MainProcess] File "/Users/zpf/.virtualenvs/jjhzk/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 1087, in execute_sql
[2020-04-06 20:53:11,600: WARNING/MainProcess] sql, params = self.as_sql()
[2020-04-06 20:53:11,600: WARNING/MainProcess] File "/Users/zpf/.virtualenvs/jjhzk/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 1395, in as_sql
[2020-04-06 20:53:11,601: WARNING/MainProcess] val = field.get_db_prep_save(val, connection=self.connection)
[2020-04-06 20:53:11,601: WARNING/MainProcess] File "/Users/zpf/.virtualenvs/jjhzk/lib/python3.6/site-packages/django/db/models/fields/__init__.py", line 793, in get_db_prep_save
[2020-04-06 20:53:11,601: WARNING/MainProcess] return self.get_db_prep_value(value, connection=connection, prepared=False)
[2020-04-06 20:53:11,601: WARNING/MainProcess] File "/Users/zpf/.virtualenvs/jjhzk/lib/python3.6/site-packages/django/db/models/fields/__init__.py", line 1436, in get_db_prep_value
[2020-04-06 20:53:11,602: WARNING/MainProcess] return connection.ops.adapt_datetimefield_value(value)
[2020-04-06 20:53:11,602: WARNING/MainProcess] File "/Users/zpf/.virtualenvs/jjhzk/lib/python3.6/site-packages/django/db/backends/mysql/operations.py", line 198, in adapt_datetimefield_value
[2020-04-06 20:53:11,602: WARNING/MainProcess] raise ValueError("MySQL backend does not support timezone-aware datetimes when USE_TZ is False.")
[2020-04-06 20:53:11,602: WARNING/MainProcess] ValueError
[2020-04-06 20:53:11,603: WARNING/MainProcess] :
[2020-04-06 20:53:11,603: WARNING/MainProcess] MySQL backend does not support timezone-aware datetimes when USE_TZ is False.
[2020-04-06 20:53:11,603: INFO/MainProcess] Writing entries...
[2020-04-06 20:53:11,603: INFO/MainProcess] Writing entries...
[2020-04-06 20:53:11,602: WARNING/MainProcess] ***raise ValueError("MySQL backend does not support timezone-aware datetimes when USE_TZ is False.")***
[2020-04-06 20:53:11,602: WARNING/MainProcess] ValueError
[2020-04-06 20:53:11,603: WARNING/MainProcess] :
[2020-04-06 20:53:11,603: WARNING/MainProcess] ***MySQL backend does not support timezone-aware datetimes when USE_TZ is False.***
网上查到的方法,大多是修改Django settings中,USE_TZ 改为 True。但是有个问题,这样修改后,所有获取时间的地方全部都要修改一次。这个工作量。。。
既然不能使用 “USE_TZ = True”的方案,那就乖乖研究源码吧。
[2020-04-06 20:53:11,602: WARNING/MainProcess] File ***"/Users/zpf/.virtualenvs/jjhzk/lib/python3.6/site-packages/django/db/backends/mysql/operations.py",*** line 198, in adapt_datetimefield_value
[2020-04-06 20:53:11,602: WARNING/MainProcess] raise ValueError("MySQL backend does not support timezone-aware datetimes when USE_TZ is False.")
[2020-04-06 20:53:11,602: WARNING/MainProcess] ValueError
[2020-04-06 20:53:11,603: WARNING/MainProcess] :
[2020-04-06 20:53:11,603: WARNING/MainProcess] MySQL backend does not support timezone-aware datetimes when USE_TZ is False.
就是这里报的错,进去看看。
def adapt_datetimefield_value(self, value):
if value is None:
return None
# Expression values are adapted by the database.
if hasattr(value, 'resolve_expression'):
return value
# MySQL doesn't support tz-aware datetimes
if timezone.is_aware(value):
if settings.USE_TZ:
value = timezone.make_naive(value, self.connection.timezone)
else:
raise ValueError("MySQL backend does not support timezone-aware datetimes when USE_TZ is False.")
return str(value)
很明显,这里加了if判断,当settings.USE_TZ = False时,会出发异常,所以。。。
简单粗暴,注释掉这些代码。
def adapt_datetimefield_value(self, value):
if value is None:
return None
# Expression values are adapted by the database.
if hasattr(value, 'resolve_expression'):
return value
# MySQL doesn't support tz-aware datetimes
if timezone.is_aware(value):
# if settings.USE_TZ:
value = timezone.make_naive(value, self.connection.timezone)
# else:
# raise ValueError("MySQL backend does not support timezone-aware datetimes when USE_TZ is False.")
return str(value)
重启服务,验证没有问题。
PS: 方法粗暴,虽解决了燃眉之急,但目前不知道有无其他影响。如果有影响,后期补充。