Django(42000):'action_time'的默认值无效

时间:2016-07-22 20:24:07

标签: mysql django django-models

尝试运行管理员迁移时(0002_logentry_remove_auto_add),我收到错误消息:

mysql.connector.errors.ProgrammingError: 1067 (42000): Invalid default value for 'action_time'

不确定是什么导致这种情况,我有一个源代码编译版本的mysql(5.5.50)可能与它有关。

使用mysql-connector-python 2.1.3运行Django 1.9.2

编辑Traceback:

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/bischoff_s/Code/venvs/gec/lib/python3.5/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
    utility.execute()
  File "/home/bischoff_s/Code/venvs/gec/lib/python3.5/site-packages/django/core/management/__init__.py", line 345, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/bischoff_s/Code/venvs/gec/lib/python3.5/site-packages/django/core/management/base.py", line 348, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/bischoff_s/Code/venvs/gec/lib/python3.5/site-packages/django/core/management/base.py", line 399, in execute
    output = self.handle(*args, **options)
  File "/home/bischoff_s/Code/venvs/gec/lib/python3.5/site-packages/django/core/management/commands/migrate.py", line 200, in handle
    executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial)
  File "/home/bischoff_s/Code/venvs/gec/lib/python3.5/site-packages/django/db/migrations/executor.py", line 92, in migrate
    self._migrate_all_forwards(plan, full_plan, fake=fake, fake_initial=fake_initial)
  File "/home/bischoff_s/Code/venvs/gec/lib/python3.5/site-packages/django/db/migrations/executor.py", line 121, in _migrate_all_forwards
    state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
  File "/home/bischoff_s/Code/venvs/gec/lib/python3.5/site-packages/django/db/migrations/executor.py", line 198, in apply_migration
    state = migration.apply(state, schema_editor)
  File "/home/bischoff_s/Code/venvs/gec/lib/python3.5/site-packages/django/db/migrations/migration.py", line 123, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  File "/home/bischoff_s/Code/venvs/gec/lib/python3.5/site-packages/django/db/migrations/operations/fields.py", line 201, in database_forwards
    schema_editor.alter_field(from_model, from_field, to_field)
  File "/home/bischoff_s/Code/venvs/gec/lib/python3.5/site-packages/django/db/backends/base/schema.py", line 482, in alter_field
    old_db_params, new_db_params, strict)
  File "/home/bischoff_s/Code/venvs/gec/lib/python3.5/site-packages/django/db/backends/base/schema.py", line 634, in _alter_field
    params,
  File "/home/bischoff_s/Code/venvs/gec/lib/python3.5/site-packages/django/db/backends/base/schema.py", line 110, in execute
    cursor.execute(sql, params)
  File "/home/bischoff_s/Code/venvs/gec/lib/python3.5/site-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
  File "/home/bischoff_s/Code/venvs/gec/lib/python3.5/site-packages/mysql/connector/django/base.py", line 227, in execute
    return self._execute_wrapper(self.cursor.execute, query, new_args)
  File "/home/bischoff_s/Code/venvs/gec/lib/python3.5/site-packages/mysql/connector/django/base.py", line 180, in _execute_wrapper
    utils.ProgrammingError(err.msg), sys.exc_info()[2])
  File "/home/bischoff_s/Code/venvs/gec/lib/python3.5/site-packages/django/utils/six.py", line 685, in reraise
    raise value.with_traceback(tb)
  File "/home/bischoff_s/Code/venvs/gec/lib/python3.5/site-packages/mysql/connector/django/base.py", line 177, in _execute_wrapper
    return method(query, args)
  File "/home/bischoff_s/Code/venvs/gec/lib/python3.5/site-packages/mysql/connector/cursor.py", line 515, in execute
    self._handle_result(self._connection.cmd_query(stmt))
  File "/home/bischoff_s/Code/venvs/gec/lib/python3.5/site-packages/mysql/connector/connection.py", line 488, in cmd_query
    result = self._handle_result(self._send_cmd(ServerCmd.QUERY, query))
  File "/home/bischoff_s/Code/venvs/gec/lib/python3.5/site-packages/mysql/connector/connection.py", line 395, in _handle_result
    raise errors.get_exception(packet)
django.db.utils.ProgrammingError: Invalid default value for 'action_time'

编辑更多:

ipdb> stmt
b"ALTER TABLE `django_admin_log` ALTER COLUMN `action_time` SET DEFAULT    '2016-07-25 17:58:03.214262+00:00'"
ipdb> self._connection.cmd_query(stmt)
*** mysql.connector.errors.ProgrammingError: 1067 (42000): Invalid   default value for 'action_time'

我不确定为什么数据库没有将此数据作为有效的默认值...

2 个答案:

答案 0 :(得分:0)

这里有点奇怪,因为传递给MySQL的默认datetime包括微秒,即使it doesn't support it也是如此。

我认为这是您的数据库驱动程序的问题,因为它本身应该剥离微秒。

答案 1 :(得分:0)

所以mysql-connector-python已经死了(对我而言),所有人都欢呼mysqlclient。显然它不再维护了。我切换到mysqlclient,它没有问题。