django.db.utils.InternalError:(1050,“表'django_content_type'已经存在”)

2024-01-07

django.db.utils.InternalError:(1050,“表'django_content_type'已经存在”)

我刚刚从我的朋友那里复制了一个项目,当我运行 makemirations 时它运行正常。但对于 -

python3 manage.py migrate 

它给出了这个错误 -

Operations to perform:
  Apply all migrations: admin, auth, balancesheet, contenttypes, dynapp, pandl2, sessions, trialbal2
Running migrations:
  Applying contenttypes.0001_initial...Traceback (most recent call last):
  File "/home/hostbooks/django1/myproject/lib/python3.6/site-packages/django/db/backends/utils.py", line 82, in _execute
    return self.cursor.execute(sql)
  File "/home/hostbooks/django1/myproject/lib/python3.6/site-packages/django/db/backends/mysql/base.py", line 74, in execute
    return self.cursor.execute(query, args)
  File "/home/hostbooks/django1/myproject/lib/python3.6/site-packages/pymysql/cursors.py", line 170, in execute
    result = self._query(query)
  File "/home/hostbooks/django1/myproject/lib/python3.6/site-packages/pymysql/cursors.py", line 328, in _query
    conn.query(q)
  File "/home/hostbooks/django1/myproject/lib/python3.6/site-packages/pymysql/connections.py", line 517, in query
    self._affected_rows = self._read_query_result(unbuffered=unbuffered)
  File "/home/hostbooks/django1/myproject/lib/python3.6/site-packages/pymysql/connections.py", line 732, in _read_query_result
    result.read()
  File "/home/hostbooks/django1/myproject/lib/python3.6/site-packages/pymysql/connections.py", line 1075, in read
    first_packet = self.connection._read_packet()
  File "/home/hostbooks/django1/myproject/lib/python3.6/site-packages/pymysql/connections.py", line 684, in _read_packet
    packet.check_error()
  File "/home/hostbooks/django1/myproject/lib/python3.6/site-packages/pymysql/protocol.py", line 220, in check_error
    err.raise_mysql_exception(self._data)
  File "/home/hostbooks/django1/myproject/lib/python3.6/site-packages/pymysql/err.py", line 109, in raise_mysql_exception
    raise errorclass(errno, errval)
pymysql.err.InternalError: (1050, "Table 'django_content_type' already exists")

上述异常是导致以下异常的直接原因:

Traceback (most recent call last):
  File "manage.py", line 21, in <module>
    main()
  File "manage.py", line 17, in main
    execute_from_command_line(sys.argv)
  File "/home/hostbooks/django1/myproject/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "/home/hostbooks/django1/myproject/lib/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/hostbooks/django1/myproject/lib/python3.6/site-packages/django/core/management/base.py", line 323, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/hostbooks/django1/myproject/lib/python3.6/site-packages/django/core/management/base.py", line 364, in execute
    output = self.handle(*args, **options)
  File "/home/hostbooks/django1/myproject/lib/python3.6/site-packages/django/core/management/base.py", line 83, in wrapped
    res = handle_func(*args, **kwargs)
  File "/home/hostbooks/django1/myproject/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 234, in handle
    fake_initial=fake_initial,
  File "/home/hostbooks/django1/myproject/lib/python3.6/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/hostbooks/django1/myproject/lib/python3.6/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/hostbooks/django1/myproject/lib/python3.6/site-packages/django/db/migrations/executor.py", line 245, in apply_migration
    state = migration.apply(state, schema_editor)
  File "/home/hostbooks/django1/myproject/lib/python3.6/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/hostbooks/django1/myproject/lib/python3.6/site-packages/django/db/migrations/operations/models.py", line 92, in database_forwards
    schema_editor.create_model(model)
  File "/home/hostbooks/django1/myproject/lib/python3.6/site-packages/django/db/backends/base/schema.py", line 307, in create_model
    self.execute(sql, params or None)
  File "/home/hostbooks/django1/myproject/lib/python3.6/site-packages/django/db/backends/base/schema.py", line 137, in execute
    cursor.execute(sql, params)
  File "/home/hostbooks/django1/myproject/lib/python3.6/site-packages/django/db/backends/utils.py", line 99, in execute
    return super().execute(sql, params)
  File "/home/hostbooks/django1/myproject/lib/python3.6/site-packages/django/db/backends/utils.py", line 67, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "/home/hostbooks/django1/myproject/lib/python3.6/site-packages/django/db/backends/utils.py", line 76, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/home/hostbooks/django1/myproject/lib/python3.6/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "/home/hostbooks/django1/myproject/lib/python3.6/site-packages/django/db/utils.py", line 89, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/home/hostbooks/django1/myproject/lib/python3.6/site-packages/django/db/backends/utils.py", line 82, in _execute
    return self.cursor.execute(sql)
  File "/home/hostbooks/django1/myproject/lib/python3.6/site-packages/django/db/backends/mysql/base.py", line 74, in execute
    return self.cursor.execute(query, args)
  File "/home/hostbooks/django1/myproject/lib/python3.6/site-packages/pymysql/cursors.py", line 170, in execute
    result = self._query(query)
  File "/home/hostbooks/django1/myproject/lib/python3.6/site-packages/pymysql/cursors.py", line 328, in _query
    conn.query(q)
  File "/home/hostbooks/django1/myproject/lib/python3.6/site-packages/pymysql/connections.py", line 517, in query
    self._affected_rows = self._read_query_result(unbuffered=unbuffered)
  File "/home/hostbooks/django1/myproject/lib/python3.6/site-packages/pymysql/connections.py", line 732, in _read_query_result
    result.read()
  File "/home/hostbooks/django1/myproject/lib/python3.6/site-packages/pymysql/connections.py", line 1075, in read
    first_packet = self.connection._read_packet()
  File "/home/hostbooks/django1/myproject/lib/python3.6/site-packages/pymysql/connections.py", line 684, in _read_packet
    packet.check_error()
  File "/home/hostbooks/django1/myproject/lib/python3.6/site-packages/pymysql/protocol.py", line 220, in check_error
    err.raise_mysql_exception(self._data)
  File "/home/hostbooks/django1/myproject/lib/python3.6/site-packages/pymysql/err.py", line 109, in raise_mysql_exception
    raise errorclass(errno, errval)
django.db.utils.InternalError: (1050, "Table 'django_content_type' already exists")


 django.db.utils.InternalError: (1050, "Table 'django_content_type' already exists")

当我打开 MySQL 使用 drop table 命令删除 'DJANGO_CONTENT_TYPE 表时,出现此错误 -

mysql> drop table django_content_type;
ERROR 1217 (23000): Cannot delete or update a parent row: a foreign key constraint fails

即我无法删除该表。

我进行了迁移,因为我对模型做了一些更改。

尽管我找到了一种替代方法来绕过这个错误,而不是通过逻辑。我创建了一个需要的数据库并将设置更改为新数据库。在这里,我将内容从初始数据库复制到另一个数据库。


对于 django3: 我收到此错误: django.db.utils.OperationalError:(1054,“'django_content_type'中的未知列'名称'”)

  1. 删除 myapp/migrations/0001_initial.py 和 0002_ .....

  2. 从 django_migrations 表中删除所有行。

    Delete * from django_migrations
    
  3. python3 manage.py makemigrations

or

python manage.py makemigrations
  1. python3 manage.py migrate --fake-initial

or

python manage.py migrate --fake-initial
  1. 我收到此错误: MySQLdb._exceptions.OperationalError:(1054,“'django_content_type'中的未知列'名称'”)

  2. 我向 django_content_type 表添加一列。

    更改表 django_content_type 添加名称 varchar(255)

  3. python3 manage.py migrate --fake-initial

  4. 出现此错误 django.db.utils.OperationalError: (1061, "Duplicate key name 'django_site_domain_a2e37b91_uniq'")

  5. 我没有对此错误采取任何措施,但我的网站运行良好。 “名称”列将被删除

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

django.db.utils.InternalError:(1050,“表'django_content_type'已经存在”) 的相关文章

  • 如何将人物传奇带到前台?

    我有一系列子图 其中每个子图都有一个图例 我想在每个子图之外与相邻子图重叠 问题在于图例位于其自己的图的 顶部 但位于相邻图的下方 Legend 不将 zorder 作为参数 所以我不知道如何解决这个问题 这是我使用过的代码 import
  • TCP打孔问题

    我尝试使用 Python 3 中概述的原则为防火墙编写一个基本的 TCP 打孔器本文 http www bford info pub net p2pnat index html 不过 我无法连接任何东西 这是代码 usr bin pytho
  • python中嵌套字典值的总和

    我有一本这样的字典 data 11L a 2 b 1 a 2 b 3 22L a 3 b 2 a 2 b 5 a 4 b 2 a 1 b 5 a 1 b 0 33L a 1 b 2 a 3 b 5 a 5 b 2 a 1 b 3 a 1 b
  • 使用 Python 将阿拉伯语或任何从右到左书写系统的字符串打印到 Linux 终端

    非常简单的例子是 city print city 我期望输出是 但实际上输出是相反的字符串 字母看起来有点不同 因为它们有开始 中间和结束形式 我无法将其粘贴到此处 因为复制粘贴会再次更正字符串的顺序 如何在 Linux 终端上正确打印阿拉
  • Django“模型”对象不可迭代

    我有一张表 其中显示了已注册的员工 我想根据他们的数据库生成一个简单的 HTML 页面 其中包括他们的姓名 id 职称等 为此 我将一个 id 传递给视图 以便它可以获取相应用户的详细信息并向我显示 一切正常 直到出现错误对象不可迭代 下面
  • Pygooglevoice登录错误

    另一个人问了这个问题 但没有回复 所以我再问一遍 我正在尝试使用 pygooglevoice API 但是当我运行 SMS py 示例脚本时 它给了我一个登录错误 我已经安装了 Enthought python 我想也许我还需要安装其他东西
  • python - 将cookie添加到cookiejar

    如何在 python 中创建 cookie 并将其添加到 CookieJar 实例 我拥有 cookie 的所有信息 名称 值 域 路径等 但我不想通过 http 请求提取新的 cookie 我尝试了这个 但看起来 SimpleCookie
  • Django 1.6 的静态文件

    我花了一整天但没有任何作用 我在这里看到了至少 20 篇关于同一主题的帖子 它们各不相同 有不同的建议 但没有一个对我有用 使用 Python 2 7 运行 Django 1 6 我正在尝试从 django 教程加载民意调查应用程序的 cs
  • 如何从 Python 3.5 降级到 3.4

    我想安装 kivy 链接在这里 https kivy org docs installation installation windows html install win dist 用于项目 但是 当尝试使用 pip 安装它所依赖的包时
  • 使用 matplotlib 设置或固定二元分布值

    I ve animated a bivariate gaussian distribution using matplotlib 我已经计算过这个distribution通过调整COV matrix来考虑特定的变量 我可以提供有关此过程的更
  • 模拟类:Mock() 还是 patch()?

    我在用mock http www voidspace org uk python mock index html使用Python 想知道这两种方法中哪一种更好 阅读 更Pythonic 方法一 只需创建一个模拟对象并使用它 代码如下 def
  • 如何打印和显示子进程 stdout 和 stderr 输出而不失真?

    也许有人可以帮助我解决这个问题 我在 SO 上看到了许多与此类似的问题 但没有一个问题同时处理标准输出和标准错误 也没有处理像我这样的情况 因此出现了这个新问题 我有一个 python 函数 它打开一个子进程 等待它完成 然后输出返回代码以
  • 尝试将 cuda 与 pytorch 一起使用时出现运行时错误 999

    我为我的 Geforce 2080 ti 安装了 Cuda 10 1 和最新的 Nvidia 驱动程序 我尝试运行一个基本脚本来测试 pytorch 是否正常工作 但出现以下错误 RuntimeError cuda runtime erro
  • Python itertools groupby 中令人不安的奇怪行为/错误?

    我在用itertools groupby解析一个短的制表符分隔的文本文件 文本文件有几列 我想做的就是对具有特定值的所有条目进行分组x在特定的列中 下面的代码对名为的列执行此操作name2 寻找变量中的值x 我尝试使用以下方法来做到这一点c
  • CryptoJS 和 Pycrypto 一起工作

    我正在使用 CryptoJS v 2 3 加密 Web 应用程序中的字符串 并且需要在服务器上使用 Python 对其进行解密 因此我使用 PyCrypto 我觉得我错过了一些东西 因为我无法让它工作 这是JS Crypto AES enc
  • 如何在 matplotlib 中第一个 x 轴的底部添加第二个 x 轴?

    我指的是已经提出的问题here https stackoverflow com questions 10514315 how to add a second x axis in matplotlib 在此示例中 用户通过将第二个轴添加到与标
  • 枚举上的 random.choice

    我想用random choice on an Enum I tried class Foo Enum a 0 b 1 c 2 bar random choice Foo 但是这段代码失败了KeyError 我怎样才能随机选择一个成员Enum
  • 执行许多插入重复键更新错误:未使用所有参数

    所以我一直在尝试使用 python 2 7 15 使用 mysql connector 执行此查询 但由于某种原因 它似乎不起作用并且总是返回错误 并非所有参数都被使用 表更新有一个主键 即 ID 这是我尝试运行此 SQL 的查询 sql
  • 对 Python 列表元素进行分组

    我有一个 python 列表 如下所示 my list 25 1 0 65 25 3 0 63 25 2 0 62 50 3 0 65 50 2 0 63 50 1 0 62 我想根据以下规则对它们进行排序 1 gt 0 65 0 62 l
  • Python Pandas:向类 pandas.core.series.Series 添加方法

    我想在 Python 中处理时间序列 因此 Pandas 的 Series 类非常完美 并且有很多有用的方法 现在我想添加一些我需要但未实现的方法 例如 假设我有兴趣添加一个方法 该方法将两次一值附加到时间序列中 让我们调用该方法appen

随机推荐

  • SysLogHandler 消息在远程服务器上分组在一行上

    我正在尝试使用 python 日志记录模块将消息记录到远程 rsyslog 服务器 消息已被接收 但它会将每条消息的消息连接在一行上 这是我的代码的示例 to syslog priority dict Level EMERGENCY eme
  • 从文件或 STDIN 读取

    我编写了一个命令行实用程序 它使用 getopt 来解析命令行上给出的参数 我还希望文件名成为可选参数 例如 grep cut 等其他实用程序中的文件名 因此 我希望它具有以下用法 tool d character f integer fi
  • Scala 多类型模式匹配

    我想知道如何使用多种类型模式匹配 我有 abstract class MyAbstract case class MyFirst extends MyAbstract case class MySecond extends MyAbstra
  • 从不在网络上的另一台计算机访问本地主机

    在你说它是骗局之前 这与this https stackoverflow com questions 9208472 connect to localhost from another computer in network this ht
  • 如何将 VC++ 静态库中的自定义二进制资源作为 dll 的一部分加载?

    我有自定义二进制资源 动画光标 希望将其作为资源存储在 Visual Studio C 的静态库中 事实证明 如果自定义二进制资源是自定义资源且位于静态库中 则它不会被 LoadCursor 加载 也不会被 FindResource 找到
  • Shim 与 Sham:有什么区别?

    垫片和假货有什么区别 包含 es5 shim min js 和 es6 shim min js 就足够了 还是还应该包含 es5 sham min js 和 es6 sham min js 根据这个 Github 页面 https gith
  • 如何从 OpenSSL 加密数据中获取初始化向量 (iv)

    免责声明 密码学新手 我有一个使用 OpenSSL 加密数据的外部进程 该进程现在使用盐 iPhone 应用程序从服务器获取该数据 将其下载到应用程序的文档目录 然后需要对其进行解密 iPhone OS 不包含 OpenSSL 库 您可以自
  • 如何使用 PHP 将一个 YouTube 视频上传到另一个 YouTube 频道

    我正在尝试实现用户可以将 Youtube 视频上传到他的 YouTube 频道的功能 从here http www phpgang com how to authenticate upload videos to youtube chann
  • NGRX/存储有效负载类型混淆

    我有以下行动 export const ActionTypes CREATE OH type ORDERHEAD Create Orderhead MODIFY SELECTED OH type ORDERHEAD Select Order
  • 使用干预将图像的 DPI 从 72 更改为 300

    我正在与laravel并使用in用于图像处理 我想增加图像的 DPI 我没有看到任何有关 DPI 的文档here http image intervention io 有什么解决办法吗php或任何其他方法php or laravel Int
  • 静态方法中的继承

    为什么下面的代码打印 Main public class Main public static void method System out println Main public static void main String args
  • 蛮力魔方

    基本上我有一个 3 x 3 网格 其中填充了两位数字 00 99 其中一些数字作为输入给出 其余数字未知 关于如何用 C 语言暴力解决此类问题 有哪些建议 EDIT 抱歉我忘记了部分问题 每行 每列和对角线的总和必须相同 我不需要任何代码
  • 在nodejs中运行mocha测试用例时出现内存不足异常

    对于单元测试我正在使用mocha最近我正在观察out of memory exception运行测试用例时 Last few GCs gt 548213 ms Scavenge 1365 3 1457 7 gt 1365 3 1457 7
  • React-google-chart 不占用选项

    我在用react google chart为了以图形形式 条形图 显示我的数据 根据要求我必须制作一个dual y axis chart 我已经制作了该图表 但问题是该图表没有占据options 它是一个Bar当我将图表作为ColumnCh
  • 如何在CRM插件中获取当前用户记录?

    我正在开发一个插件 每当调用插件时 我需要获取当前用户信息 有什么办法可以找回它吗 该信息可在 PluginExecutionContext 中找到 下面的代码来自您的插件必须实现的 Execute 方法 public void Execu
  • 如何在 Android 版 Chrome 中强制硬重新加载

    在桌面版 Chrome 中 我可以在开发工具中选择在打开开发工具时完全禁用缓存 并且可以选择在长按重新加载按钮时手动执行硬重新加载 在开发工具打开的情况下 Android 版 Chrome 有这样的技术吗 我没有找到任何设置 当我在开发时想
  • 为 Android 构建内核模块

    我需要将 FTDI USB 模块添加到 Android 内核 Android 2 3 1 Linux 2 6 32 因此我获得了 2 6 32 内核并尝试构建该模块 make modules ARCH arm CROSS COMPILE a
  • 将 PowerShell 变量传递到脚本块

    我正在尝试获取 PowerShell 变量并将它们应用到脚本块 param string username throw Blackberry Admin User Name is required string password throw
  • PostgreSQL 使用 tf-idf 吗?

    我想知道 PostgreSQL 9 3 中使用 GIN GiST 索引的全文搜索是否使用 tf idf 术语频率 逆文档频率 特别是 在我的短语列中 我有一些更受欢迎的单词 而有些则非常独特 即名称 我想对这些列建立索引 以便匹配的唯一单词
  • django.db.utils.InternalError:(1050,“表'django_content_type'已经存在”)

    django db utils InternalError 1050 表 django content type 已经存在 我刚刚从我的朋友那里复制了一个项目 当我运行 makemirations 时它运行正常 但对于 python3 ma