- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我无法从 django- 运行 makemigrations
、migrate
或其他任何内容(flush
、reset_db
)扩展)如果我的 INSTALLED_APPS 中有某个应用程序。
该应用程序名为 issues
并且有一个模型:
class Issue(models.Model):
title = models.CharField(max_length=255)
description = models.CharField(max_length=1000)
sent = models.BooleanField()
它之前工作正常(makemigrations 和 migrate 运行良好,我可以正确使用应用程序/模型),直到我尝试添加:
severity = models.IntegerField()
并尝试运行 makemigrations。我不再有错误或记得它,但从那时起,即使从模型中删除 severity
之后,一切都被破坏了。
如果我从 settings.py 中删除 issues
应用程序,一切都会正常。
我得到的错误:
madjura@madjura-E6228:~/workspace/budget/src$ python3.5 manage.py makemigrationsTraceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/usr/local/lib/python3.5/dist-packages/django/db/backends/sqlite3/base.py", line 337, in execute
return Database.Cursor.execute(self, query, params)
sqlite3.OperationalError: no such table: issues_issue
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.5/dist-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.5/dist-packages/django/core/management/__init__.py", line 341, in execute
django.setup()
File "/usr/local/lib/python3.5/dist-packages/django/__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/local/lib/python3.5/dist-packages/django/apps/registry.py", line 115, in populate
app_config.ready()
File "/home/madjura/workspace/budget/src/issues/apps.py", line 16, in ready
issues.models.Issue.objects.check_and_send_unsent_issues()
File "/home/madjura/workspace/budget/src/issues/models.py", line 18, in check_and_send_unsent_issues
for issue in issues:
File "/usr/local/lib/python3.5/dist-packages/django/db/models/query.py", line 256, in __iter__
self._fetch_all()
File "/usr/local/lib/python3.5/dist-packages/django/db/models/query.py", line 1087, in _fetch_all
self._result_cache = list(self.iterator())
File "/usr/local/lib/python3.5/dist-packages/django/db/models/query.py", line 54, in __iter__
results = compiler.execute_sql()
File "/usr/local/lib/python3.5/dist-packages/django/db/models/sql/compiler.py", line 835, in execute_sql
cursor.execute(sql, params)
File "/usr/local/lib/python3.5/dist-packages/django/db/backends/utils.py", line 79, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "/usr/local/lib/python3.5/dist-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/usr/local/lib/python3.5/dist-packages/django/db/utils.py", line 94, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/usr/local/lib/python3.5/dist-packages/django/utils/six.py", line 685, in reraise
raise value.with_traceback(tb)
File "/usr/local/lib/python3.5/dist-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/usr/local/lib/python3.5/dist-packages/django/db/backends/sqlite3/base.py", line 337, in execute
return Database.Cursor.execute(self, query, params)
django.db.utils.OperationalError: no such table: issues_issue
虽然问题出现在 INSTALLED_APPS 中,但我在运行 migrate、flush 和 reset_db 时遇到了相同的错误。
我尝试运行flush和reset_db,并从INSTALLED_APPS中删除问题,但这并没有解决问题。
我尝试执行上述操作,然后运行 makemigrations 和 migrate,这也不起作用。一旦我将问题放回到 INSTALLED_APPS 中,一切就都坏了。
我该如何解决这个问题?
编辑:
也许相关,问题模型有一个具有以下功能的 Manager:
class IssueManager(models.Manager):
"""Manager for the Issue class."""
def check_and_send_unsent_issues(self):
"""
Checks for unsent Issue objects (Issue.sent = False) and attempts
to send them.
Issues that have been sent are deleted.
If the issue fails to be sent for whatever reason, it is not deleted.
Does nothing if there are no unsent issues.
This method is called once when the server starts.
"""
issues = self.get_queryset().filter(sent=False)
for issue in issues:
try:
make_issue(issue.title, issue.description)
issue.delete()
except PostIssueException:
pass
使用 apps.py 检查未发送的问题并将其发布到 Gitlab 上。
编辑2:
通过注释以下行解决了问题,该行出现在我的 apps.py
的 ready()
中:
issues.models.Issue.objects.check_and_send_unsent_issues()
这不知何故导致事情破裂,我不明白为什么。有人可以解释一下吗?
最佳答案
尝试将 import issues.models
行移至 def read()
以防止过早加载模型。
关于python - Django - 无法运行 makemigrations : "no such table" even after running reset_db,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42341965/
我正在使用 Django 1.9.6。我最近删除了我的迁移并运行了 migrate --run-syncdb和 makemigrations my_app .今天,我为我的一个模型添加了一个新字段:
我正在使用 Django 1.8.4。由于我的项目仍在 build 中,我经常删除所有迁移脚本,然后重新运行 makemigrations生成初始迁移脚本。 我找到了 makemigrations将为
除了向模型添加/删除/修改字段之外,当我向模型添加或修改方法时,Django 还会检测到更改。 所以我的问题是每次在模型中更改或添加新方法时都应该运行 makemigrations 吗? 最佳答案 当
我已将 Django 项目设置为使用两个数据库。一个是只读的,另一个是项目其余部分的“默认”django 数据库。 以下是设置: DATABASES = { 'default': {
我只是按照这个程序: makemigrations (成功) migrate (成功) 复制另一台服务器上的应用程序(带有迁移文件) 在该服务器上创建一个新的空数据库 migrate (成功,它创建了
我想知道我们如何在 django 中处理数据库迁移,而生产中的站点在开发时我们停止服务器然后在数据库中进行更改然后重新运行服务器我认为这可能是一个愚蠢的问题但我自己学习并且不能提前弄清楚谢谢。 最佳答
我想在我的模型中向现有字段添加一些 db_index。我刚刚添加了 db_index=True到模型。 我在想我需要运行 python manage.py migrate将它们应用到数据库中。我的问题
我正在使用django,现在我将python文件从custom_fields重命名为fields并更改模型类和模型类正在使用来自 fields 文件的字段,但是当我运行 python manage.p
我的 makemigrations 命令有问题。 注意:到目前为止,我已经成功地进行了迁移,所以这不是我第一次尝试对该项目进行迁移。 我在 INSTALLED_APPS 中有我的项目。 问题:由于某种
Django 1.11。我最近将以下模块添加到 myapp.models: from django.db import models from ordered_model.models import
我正在尝试一个简单的模型继承: class Product(models.Model): creation_date = models.DateTimeField(auto_now_add=T
由于 windows10 初始化,我的所有 SQL 模式都被删除了。所以,我想用已经存在的 django 项目代码(有这么多行......)运行 makemigrations。但是“python ma
使用 Django 1.7,每当我执行 makemigrations 时,我都会对其中一个模型进行更改: (venv) >> python manage.py makemigrations myapp
我有一个 python2.7 django 项目(我知道,我在 20 世纪!),其中有一些模型。我需要重写 makemigrations,以便迁移文件名的格式为 0001.py、0002.py 等,而
我有一个 python2.7 django 项目(我知道,我在 20 世纪!),其中有一些模型。我需要重写 makemigrations,以便迁移文件名的格式为 0001.py、0002.py 等,而
我使用的如下,我定义了一个自定义 JSONField 类型并向其添加了一个自定义验证器类。 models.py json_ctn = JsonField(verbose_name=_('Json'),
我想迁移game.characters INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'd
我的问题是:调用manage makemigrations实际上做了什么? 我知道它会创建迁移文件,但是如何创建呢?它如何跟踪自上次迁移以来发生的变化?它是否直接将模型的当前状态与数据库进行比较?它是
我有一个用 Django 1.10.7 和 mysql 14.14 Distrib 5.5.54 构建的 django 项目 如果我这样做: $ python manage.py makemigrat
我错误地删除了路径 projectName/appName/migrations 下的所有 .py 文件,它包括: 0001_initial.py 0011_auto_20150918_0723.py
我是一名优秀的程序员,十分优秀!