在Django中刷新数据库

在Django中刷新数据库,django,Django,我正在django中设置一个数据库,在尝试刷新数据库时,出现以下错误: You have requested a flush of the database. This will IRREVERSIBLY DESTROY all data currently in the "/home/luc/projects/PySorge/API/db.sqlite3" database, and return each table to an empty state. Are yo

我正在django中设置一个数据库,在尝试刷新数据库时,出现以下错误:

  You have requested a flush of the database.
This will IRREVERSIBLY DESTROY all data currently in the "/home/luc/projects/PySorge/API/db.sqlite3" database,
and return each table to an empty state.
Are you sure you want to do this?
 
    Type yes to continue, or no to cancel: yes
Traceback (most recent call last):
  File "/home/luc/.local/lib/python3.9/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "/home/luc/.local/lib/python3.9/site-packages/django/db/backends/sqlite3/base.py", line 413, in execute
    return Database.Cursor.execute(self, query, params)
sqlite3.IntegrityError: NOT NULL constraint failed: django_content_type.name
 
The above exception was the direct cause of the following exception:
 
Traceback (most recent call last):
  File "/home/luc/projects/PySorge/API/manage.py", line 22, in <module>
    main()
  File "/home/luc/projects/PySorge/API/manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "/home/luc/.local/lib/python3.9/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "/home/luc/.local/lib/python3.9/site-packages/django/core/management/__init__.py", line 395, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/luc/.local/lib/python3.9/site-packages/django/core/management/base.py", line 330, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/luc/.local/lib/python3.9/site-packages/django/core/management/base.py", line 371, in execute
    output = self.handle(*args, **options)
  File "/home/luc/.local/lib/python3.9/site-packages/django/core/management/commands/flush.py", line 80, in handle
    emit_post_migrate_signal(verbosity, interactive, database)
  File "/home/luc/.local/lib/python3.9/site-packages/django/core/management/sql.py", line 48, in emit_post_migrate_signal
    models.signals.post_migrate.send(
  File "/home/luc/.local/lib/python3.9/site-packages/django/dispatch/dispatcher.py", line 177, in send
    return [
  File "/home/luc/.local/lib/python3.9/site-packages/django/dispatch/dispatcher.py", line 178, in <listcomp>
    (receiver, receiver(signal=self, sender=sender, **named))
  File "/home/luc/.local/lib/python3.9/site-packages/django/contrib/auth/management/__init__.py", line 42, in create_permissions
    create_contenttypes(app_config, verbosity=verbosity, interactive=interactive, using=using, apps=apps, **kwargs)
  File "/home/luc/.local/lib/python3.9/site-packages/django/contrib/contenttypes/management/__init__.py", line 132, in create_contenttypes
    ContentType.objects.using(using).bulk_create(cts)
  File "/home/luc/.local/lib/python3.9/site-packages/django/db/models/query.py", line 506, in bulk_create
    returned_columns = self._batched_insert(
  File "/home/luc/.local/lib/python3.9/site-packages/django/db/models/query.py", line 1277, in _batched_insert
    self._insert(item, fields=fields, using=self.db, ignore_conflicts=ignore_conflicts)
  File "/home/luc/.local/lib/python3.9/site-packages/django/db/models/query.py", line 1254, in _insert
    return query.get_compiler(using=using).execute_sql(returning_fields)
  File "/home/luc/.local/lib/python3.9/site-packages/django/db/models/sql/compiler.py", line 1397, in execute_sql
    cursor.execute(sql, params)
  File "/home/luc/.local/lib/python3.9/site-packages/django/db/backends/utils.py", line 98, in execute
    return super().execute(sql, params)
  File "/home/luc/.local/lib/python3.9/site-packages/django/db/backends/utils.py", line 66, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "/home/luc/.local/lib/python3.9/site-packages/django/db/backends/utils.py", line 75, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/home/luc/.local/lib/python3.9/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "/home/luc/.local/lib/python3.9/site-packages/django/db/utils.py", line 90, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/home/luc/.local/lib/python3.9/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "/home/luc/.local/lib/python3.9/site-packages/django/db/backends/sqlite3/base.py", line 413, in execute
    return Database.Cursor.execute(self, query, params)
django.db.utils.IntegrityError: NOT NULL constraint failed: django_content_type.name
您已请求刷新数据库。
这将不可逆转地破坏“/home/luc/projects/PySorge/API/db.sqlite3”数据库中当前的所有数据,
并将每个表返回到空状态。
你确定要这样做吗?
键入yes继续,或键入no取消:yes
回溯(最近一次呼叫最后一次):
文件“/home/luc/.local/lib/python3.9/site packages/django/db/backends/utils.py”,第84行,在
返回self.cursor.execute(sql,params)
文件“/home/luc/.local/lib/python3.9/site packages/django/db/backends/sqlite3/base.py”,第413行,在execute中
返回Database.Cursor.execute(self、query、params)
sqlite3.IntegrityError:非空约束失败:django\u content\u type.name
上述异常是以下异常的直接原因:
回溯(最近一次呼叫最后一次):
文件“/home/luc/projects/PySorge/API/manage.py”,第22行,在
main()
文件“/home/luc/projects/PySorge/API/manage.py”,第18行,主视图
从命令行(sys.argv)执行命令
文件“/home/luc/.local/lib/python3.9/site packages/django/core/management/_init__.py”,第401行,从命令行执行
utility.execute()
文件“/home/luc/.local/lib/python3.9/site packages/django/core/management/_init__.py”,第395行,在execute中
self.fetch_命令(子命令)。从_argv(self.argv)运行_
文件“/home/luc/.local/lib/python3.9/site packages/django/core/management/base.py”,第330行,在运行时从
self.execute(*args,**cmd_选项)
文件“/home/luc/.local/lib/python3.9/site packages/django/core/management/base.py”,第371行,在execute中
输出=self.handle(*args,**选项)
handle中的文件“/home/luc/.local/lib/python3.9/site packages/django/core/management/commands/flush.py”,第80行
发出后迁移信号(详细、交互式、数据库)
文件“/home/luc/.local/lib/python3.9/site packages/django/core/management/sql.py”,第48行,在emit\u post\u migrate\u信号中
models.signals.post_migrate.send(
文件“/home/luc/.local/lib/python3.9/site packages/django/dispatch/dispatcher.py”,第177行,在send中
返回[
文件“/home/luc/.local/lib/python3.9/site packages/django/dispatch/dispatcher.py”,第178行,在
(接收者,接收者(信号=自身,发送者=发送者,**命名))
文件“/home/luc/.local/lib/python3.9/site packages/django/contrib/auth/management/_init__.py”,第42行,位于创建权限中
创建内容类型(app\u config,verbosity=verbosity,interactive=interactive,using=using,apps=apps,**kwargs)
文件“/home/luc/.local/lib/python3.9/site packages/django/contrib/contenttypes/management/_init__.py”,第132行,在create_contenttypes中
ContentType.objects.using(using).bulk\u create(cts)
文件“/home/luc/.local/lib/python3.9/site packages/django/db/models/query.py”,第506行,批量创建
返回的列=self.\u批处理\u插入(
文件“/home/luc/.local/lib/python3.9/site packages/django/db/models/query.py”,第1277行,分批插入
self.\u插入(项,字段=字段,使用=self.db,忽略\u冲突=忽略\u冲突)
文件“/home/luc/.local/lib/python3.9/site packages/django/db/models/query.py”,第1254行,插入
return query.get\u编译器(using=using).execute\u sql(返回\u字段)
文件“/home/luc/.local/lib/python3.9/site packages/django/db/models/sql/compiler.py”,第1397行,在execute\u sql中
cursor.execute(sql,params)
文件“/home/luc/.local/lib/python3.9/site packages/django/db/backends/utils.py”,执行中的第98行
return super().execute(sql,params)
文件“/home/luc/.local/lib/python3.9/site packages/django/db/backends/utils.py”,执行中的第66行
返回self.\u使用包装器执行(sql,params,many=False,executor=self.\u execute)
文件“/home/luc/.local/lib/python3.9/site packages/django/db/backends/utils.py”,第75行,使用包装器执行
返回执行器(sql、参数、多个、上下文)
文件“/home/luc/.local/lib/python3.9/site packages/django/db/backends/utils.py”,第84行,在
返回self.cursor.execute(sql,params)
文件“/home/luc/.local/lib/python3.9/site packages/django/db/utils.py”,第90行,在退出时__
使用exc_值的_回溯(回溯)提高dj_exc_值
文件“/home/luc/.local/lib/python3.9/site packages/django/db/backends/utils.py”,第84行,在
返回self.cursor.execute(sql,params)
文件“/home/luc/.local/lib/python3.9/site packages/django/db/backends/sqlite3/base.py”,第413行,在execute中
返回Database.Cursor.execute(self、query、params)
django.db.utils.IntegrityError:非空约束失败:django\u content\u type.name
尝试迁移时,发生以下错误:

   Operations to perform:
  Apply all migrations: admin, api, auth, contenttypes, sessions
Running migrations:
  Applying api.0001_initial...Traceback (most recent call last):
  File "/home/luc/.local/lib/python3.9/site-packages/django/db/backends/utils.py", line 82, in _execute
    return self.cursor.execute(sql)
  File "/home/luc/.local/lib/python3.9/site-packages/django/db/backends/sqlite3/base.py", line 411, in execute
    return Database.Cursor.execute(self, query)
sqlite3.OperationalError: duplicate column name: ID
 
The above exception was the direct cause of the following exception:
 
Traceback (most recent call last):
  File "/home/luc/projects/PySorge/API/manage.py", line 22, in <module>
    main()
  File "/home/luc/projects/PySorge/API/manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "/home/luc/.local/lib/python3.9/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "/home/luc/.local/lib/python3.9/site-packages/django/core/management/__init__.py", line 395, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/luc/.local/lib/python3.9/site-packages/django/core/management/base.py", line 330, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/luc/.local/lib/python3.9/site-packages/django/core/management/base.py", line 371, in execute
    output = self.handle(*args, **options)
  File "/home/luc/.local/lib/python3.9/site-packages/django/core/management/base.py", line 85, in wrapped
    res = handle_func(*args, **kwargs)
  File "/home/luc/.local/lib/python3.9/site-packages/django/core/management/commands/migrate.py", line 243, in handle
    post_migrate_state = executor.migrate(
  File "/home/luc/.local/lib/python3.9/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 "/home/luc/.local/lib/python3.9/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 "/home/luc/.local/lib/python3.9/site-packages/django/db/migrations/executor.py", line 227, in apply_migration
    state = migration.apply(state, schema_editor)
  File "/home/luc/.local/lib/python3.9/site-packages/django/db/migrations/migration.py", line 124, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  File "/home/luc/.local/lib/python3.9/site-packages/django/db/migrations/operations/models.py", line 92, in database_forwards
    schema_editor.create_model(model)
  File "/home/luc/.local/lib/python3.9/site-packages/django/db/backends/base/schema.py", line 324, in create_model
    self.execute(sql, params or None)
  File "/home/luc/.local/lib/python3.9/site-packages/django/db/backends/base/schema.py", line 142, in execute
    cursor.execute(sql, params)
  File "/home/luc/.local/lib/python3.9/site-packages/django/db/backends/utils.py", line 98, in execute
    return super().execute(sql, params)
  File "/home/luc/.local/lib/python3.9/site-packages/django/db/backends/utils.py", line 66, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "/home/luc/.local/lib/python3.9/site-packages/django/db/backends/utils.py", line 75, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/home/luc/.local/lib/python3.9/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "/home/luc/.local/lib/python3.9/site-packages/django/db/utils.py", line 90, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/home/luc/.local/lib/python3.9/site-packages/django/db/backends/utils.py", line 82, in _execute
    return self.cursor.execute(sql)
  File "/home/luc/.local/lib/python3.9/site-packages/django/db/backends/sqlite3/base.py", line 411, in execute
    return Database.Cursor.execute(self, query)
django.db.utils.OperationalError: duplicate column name: ID
 
要执行的操作:
应用所有迁移:管理、api、身份验证、内容类型、会话
运行迁移:
应用api.0001_初始…回溯(最近一次调用最后一次):
文件“/home/luc/.local/lib/python3.9/site packages/django/db/backends/utils.py”,第82行,在
返回self.cursor.execute(sql)
文件“/home/luc/.local/lib/python3.9/site packages/django/db/backends/sqlite3/base.py”,第411行,在execute中
返回Database.Cursor.execute(self,query)
sqlite3.0错误:重复的列名:ID
上述异常是以下异常的直接原因:
回溯(最近一次呼叫最后一次):
文件“/home/luc/projects/PySorge/API/manage.py”,第22行,在
main()
文件“/home/luc/projects/PySorge/API/manage.py”,第18行,主视图
从命令行(sys.argv)执行命令
文件“/home/luc/.local/lib/python3.9/site packages/django/core/management/_init__.py”,第401行,从命令行执行
utility.execute()
文件“/home/luc/.local/lib/python3.9/site packages/django/core/management/_init__.py”,第395行,在execute中
self.fetch_命令(子命令)。从_argv(self.argv)运行_
文件“/home/luc/.local/lib/python3.9/site packages/django/core/management/base.py”,li
python manage.py reset_db