您现在的位置是: 网站首页> 学习笔记> Django Django

django在执行migrate时抛异常:django.db.utils.OperationalError: (1824, "Failed to open the referenced table 'auth_group'")

2024-07-06 [python] [django] 323人已围观

如题,新建的项目,因为修改了,在做数据库迁移时抛如下异常: > python .\manage.py migrate
Operations to perform: Apply all migrations: admin, auth, contenttypes, sessions, tenants Running migrations: Applying contenttypes.0001_initial... OK Applying contenttypes.0002_remove_content_type_name... OK Applying auth.0001_initial... OK Applying auth.0002_alter_permission_name_max_length... OK Applying auth.0003_alter_user_email_max_length... OK Applying auth.0004_alter_user_username_opts... OK Applying auth.0005_alter_user_last_login_null... OK Applying auth.0006_require_contenttypes_0002... OK Applying auth.0007_alter_validators_add_error_messages... OK Applying auth.0008_alter_user_username_max_length... OK Applying auth.0009_alter_user_last_name_max_length... OK Applying auth.0010_alter_group_name_max_length... OK Applying auth.0011_update_proxy_permissions... OK Applying auth.0012_alter_user_first_name_max_length... OK Applying tenants.0001_initial...Traceback (most recent call last): File "D:\pyvenv\orderingsystems\lib\site-packages\django\db\backends\utils.py", line 89, in _execute return self.cursor.execute(sql, params) File "D:\pyvenv\orderingsystems\lib\site-packages\django\db\backends\mysql\base.py", line 75, in execute return self.cursor.execute(query, args) File "D:\pyvenv\orderingsystems\lib\site-packages\MySQLdb\cursors.py", line 179, in execute res = self._query(mogrified_query) File "D:\pyvenv\orderingsystems\lib\site-packages\MySQLdb\cursors.py", line 330, in _query db.query(q) File "D:\pyvenv\orderingsystems\lib\site-packages\MySQLdb\connections.py", line 261, in query _mysql.connection.query(self, query) MySQLdb.OperationalError: (1824, "Failed to open the referenced table 'auth_group'")

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "D:\codes\orderingsystems\manage.py", line 22, in <module>
    main()
  File "D:\codes\orderingsystems\manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "D:\pyvenv\orderingsystems\lib\site-packages\django\core\management\__init__.py", line 442, in execute_from_command_line
    utility.execute()
  File "D:\pyvenv\orderingsystems\lib\site-packages\django\core\management\__init__.py", line 436, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "D:\pyvenv\orderingsystems\lib\site-packages\django\core\management\base.py", line 412, in run_from_argv
    self.execute(*args, **cmd_options)
  File "D:\pyvenv\orderingsystems\lib\site-packages\django\core\management\base.py", line 458, in execute
    output = self.handle(*args, **options)
  File "D:\pyvenv\orderingsystems\lib\site-packages\django\core\management\base.py", line 106, in wrapper
    res = handle_func(*args, **kwargs)
  File "D:\pyvenv\orderingsystems\lib\site-packages\django\core\management\commands\migrate.py", line 356, in handle
    post_migrate_state = executor.migrate(
  File "D:\pyvenv\orderingsystems\lib\site-packages\django\db\migrations\executor.py", line 135, in migrate
    state = self._migrate_all_forwards(
  File "D:\pyvenv\orderingsystems\lib\site-packages\django\db\migrations\executor.py", line 167, in _migrate_all_forwards
    state = self.apply_migration(
  File "D:\pyvenv\orderingsystems\lib\site-packages\django\db\migrations\executor.py", line 249, in apply_migration
    with self.connection.schema_editor(
  File "D:\pyvenv\orderingsystems\lib\site-packages\django\db\backends\base\schema.py", line 166, in __exit__
    self.execute(sql)
  File "D:\pyvenv\orderingsystems\lib\site-packages\django\db\backends\base\schema.py", line 201, in execute
    cursor.execute(sql, params)
  File "D:\pyvenv\orderingsystems\lib\site-packages\django\db\backends\utils.py", line 102, in execute
    return super().execute(sql, params)
  File "D:\pyvenv\orderingsystems\lib\site-packages\django\db\backends\utils.py", line 67, in execute
    return self._execute_with_wrappers(
  File "D:\pyvenv\orderingsystems\lib\site-packages\django\db\backends\utils.py", line 80, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "D:\pyvenv\orderingsystems\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
    with self.db.wrap_database_errors:
  File "D:\pyvenv\orderingsystems\lib\site-packages\django\db\backends\mysql\base.py", line 75, in execute
    return self.cursor.execute(query, args)
  File "D:\pyvenv\orderingsystems\lib\site-packages\MySQLdb\cursors.py", line 179, in execute
    res = self._query(mogrified_query)
  File "D:\pyvenv\orderingsystems\lib\site-packages\MySQLdb\cursors.py", line 330, in _query
    db.query(q)
  File "D:\pyvenv\orderingsystems\lib\site-packages\MySQLdb\connections.py", line 261, in query
    _mysql.connection.query(self, query)
django.db.utils.OperationalError: (1824, "Failed to open the referenced table 'auth_group'")

目前使用的解决方法:

在数据库中执行以下命令可解决: set GLOBAL foreign_key_checks=0;

文章评论

暂无评论

添加评论





本栏推荐

站点信息

  • 建站时间:2021-01-01
  • 网站程序:Django 3.1.2
  • 文章统计:53篇
  • 文章评论:31条
  • 统计数据