Django使迁移失败。编程错误:xxxxx列不存在

2024-06-08 22:01:00 发布

您现在位置:Python中文网/ 问答频道 /正文

Django 2.0、python3.5、postgres

我试图在django中的一个模型上创建一个新的boolean字段。问题是,当我运行makemigrations时,它会抛出一个

psycopg2.ProgrammingError: column core_marca.eh_maiores_bancos does not exist。在

但我正试图创建一个eh_maiores_bancos专栏。 在创建迁移文件之前发生此错误。我以前在其他模型中也遇到过同样的问题,并通过注释引起异常的代码片段来解决,但随着它不断发生,我正在寻找比查看日志和手动注释导致错误的行更好的解决方案。在

注意:导致错误的代码段位于完全不同的文件中视图.py在我的API模块中,我有一个函数,它返回我所拥有的模型的所有对象的列表。在

我尝试删除数据库,重新创建它,删除迁移文件,然后创建迁移和迁移,但仍然失败。我还尝试更改代码的导入顺序,即安装的应用程序的顺序,添加一个if not 'makemigrations' in sys.argv:以防止代码在我创建迁移时运行,但它只会创建一个不同的错误。在

我在django文档中找不到这方面的内容。我发现的另一个stackoverflow问题有一个类似的问题(Django Migration Error: Column does not exist)有答案,但所有这些问题都告诉我注释引起问题的代码并进行迁移。在

运行makemigrations时的日志是:

Traceback (most recent call last):
##Removed a few lines of traceback. just django core code


  File "/home/esb/projects/ts2/esb-python/gerentesonhos/apps/API/base/urls.py", line 2, in <module>
    from .views import *
  File "/home/esb/projects/ts2/esb-python/gerentesonhos/apps/API/base/views.py", line 126, in <module>
    class MarcaList(generics.ListCreateAPIView):
  File "/home/esb/projects/ts2/esb-python/gerentesonhos/apps/API/base/views.py", line 175, in MarcaList
    for m in marcas:
  File "/home/esb/projects/ts2/esb-env/lib/python3.5/site-packages/django/db/models/query.py", line 272, in __iter__
    self._fetch_all()
  File "/home/esb/projects/ts2/esb-env/lib/python3.5/site-packages/django/db/models/query.py", line 1179, in _fetch_all
    self._result_cache = list(self._iterable_class(self))
  File "/home/esb/projects/ts2/esb-env/lib/python3.5/site-packages/django/db/models/query.py", line 53, in __iter__
    results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
  File "/home/esb/projects/ts2/esb-env/lib/python3.5/site-packages/django/db/models/sql/compiler.py", line 1067, in execute_sql
    cursor.execute(sql, params)
  File "/home/esb/projects/ts2/esb-env/lib/python3.5/site-packages/django/db/backends/utils.py", line 68, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "/home/esb/projects/ts2/esb-env/lib/python3.5/site-packages/django/db/backends/utils.py", line 77, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/home/esb/projects/ts2/esb-env/lib/python3.5/site-packages/django/db/backends/utils.py", line 85, in _execute
    return self.cursor.execute(sql, params)
  File "/home/esb/projects/ts2/esb-env/lib/python3.5/site-packages/django/db/utils.py", line 89, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/home/esb/projects/ts2/esb-env/lib/python3.5/site-packages/django/db/backends/utils.py", line 85, in _execute
    return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: column core_marca.eh_maiores_bancos does not exist
LINE 1: ..._emprestimo", "core_marca"."tipo_instituicao_id", "core_marc...

Tags: djangoinpyselfenvhomeexecutedb