新人一枚,最近在学习django。在执行mysql同步的时候发生错误。
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 22, in
main()
File "manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "D:\PYTHON\lib\site-packages\django\core\management\__init__.py", line 419, in execute_from_command_line
utility.execute()
File "D:\PYTHON\lib\site-packages\django\core\management\__init__.py", line 413, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "D:\PYTHON\lib\site-packages\django\core\management\base.py", line 354, in run_from_argv
self.execute(*args, **cmd_options)
File "D:\PYTHON\lib\site-packages\django\core\management\base.py", line 398, in execute
output = self.handle(*args, **options)
File "D:\PYTHON\lib\site-packages\django\core\management\base.py", line 89, in wrapped
res = handle_func(*args, **kwargs)
File "D:\PYTHON\lib\site-packages\django\core\management\commands\migrate.py", line 244, in handle
post_migrate_state = executor.migrate(
File "D:\PYTHON\lib\site-packages\django\db\migrations\executor.py", line 117, in migrate
state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
File "D:\PYTHON\lib\site-packages\django\db\migrations\executor.py", line 147, in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
File "D:\PYTHON\lib\site-packages\django\db\migrations\executor.py", line 229, in apply_migration
self.record_migration(migration)
File "D:\PYTHON\lib\site-packages\django\db\migrations\executor.py", line 244, in record_migration
self.recorder.record_applied(migration.app_label, migration.name)
File "D:\PYTHON\lib\site-packages\django\db\migrations\recorder.py", line 87, in record_applied
self.migration_qs.create(app=app, name=name)
File "D:\PYTHON\lib\site-packages\django\db\models\query.py", line 453, in create
obj.save(force_insert=True, using=self.db)
File "D:\PYTHON\lib\site-packages\django\db\models\base.py", line 726, in save
self.save_base(using=using, force_insert=force_insert,
File "D:\PYTHON\lib\site-packages\django\db\models\base.py", line 763, in save_base
updated = self._save_table(
File "D:\PYTHON\lib\site-packages\django\db\models\base.py", line 868, in _save_table
results = self._do_insert(cls._base_manager, using, fields, returning_fields, raw)
File "D:\PYTHON\lib\site-packages\django\db\models\base.py", line 906, in _do_insert
return manager._insert(
File "D:\PYTHON\lib\site-packages\django\db\models\manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "D:\PYTHON\lib\site-packages\django\db\models\query.py", line 1270, in _insert
return query.get_compiler(using=using).execute_sql(returning_fields)
File "D:\PYTHON\lib\site-packages\django\db\models\sql\compiler.py", line 1416, in execute_sql
cursor.execute(sql, params)
File "D:\PYTHON\lib\site-packages\django\db\backends\utils.py", line 98, in execute
return super().execute(sql, params)
File "D:\PYTHON\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:\PYTHON\lib\site-packages\django\db\backends\utils.py", line 75, in _execute_with_wrappers
return executor(sql, params, many, context)
File "D:\PYTHON\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "D:\PYTHON\lib\site-packages\django\db\utils.py", line 90, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "D:\PYTHON\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "D:\PYTHON\lib\site-packages\django\db\backends\mysql\base.py", line 73, in execute
return self.cursor.execute(query, args)
File "D:\PYTHON\lib\site-packages\pymysql\cursors.py", line 148, in execute
result = self._query(query)
File "D:\PYTHON\lib\site-packages\pymysql\cursors.py", line 310, in _query
conn.query(q)
File "D:\PYTHON\lib\site-packages\pymysql\connections.py", line 548, in query
self._affected_rows = self._read_query_result(unbuffered=unbuffered)
File "D:\PYTHON\lib\site-packages\pymysql\connections.py", line 775, in _read_query_result
result.read()
File "D:\PYTHON\lib\site-packages\pymysql\connections.py", line 1156, in read
first_packet = self.connection._read_packet()
File "D:\PYTHON\lib\site-packages\pymysql\connections.py", line 725, in _read_packet
packet.raise_for_error()
File "D:\PYTHON\lib\site-packages\pymysql\protocol.py", line 221, in raise_for_error
err.raise_mysql_exception(self._data)
File "D:\PYTHON\lib\site-packages\pymysql\err.py", line 143, in raise_mysql_exception
raise errorclass(errno, errval)
django.db.utils.OperationalError: (1665, 'Cannot execute statement: impossible to write to binary log since BINLOG_FORMAT = STATEMENT and at least one table uses a storage engine limited to row-based log
ging. InnoDB is limited to row-logging when transaction isolation level is READ COMMITTED or READ UNCOMMITTED.')
刚开是以为是中途的操作配置步骤的问题。然而整了挺久的,还是没有发现有是什么错误。
最后直接根据所报的问题进行搜索解决。
pymysql.err.OperationalError: (1665, 'Cannot execute statement: impossible to write to binary log since BINLOG_FORMAT = STATEMENT and at least one table uses a storage engine limited to row-based logging
. InnoDB is limited to row-logging when transaction isolation level is READ COMMITTED or READ UNCOMMITTED.')
解决方案执行以下语句。
SET SESSION binlog_format = 'ROW';
SET GLOBAL binlog_format = 'ROW';
之后在执行:
python manage.py migrate
就同步成功了。
很惊讶会是因为数据库那边的设置问题。