设置新的全新虚拟环境和postgres db,甚至不能进行迁移。系统在其他2台PC上运行良好
已安装python3.5
创建了虚拟环境
应用“ requirements.txt”已成功安装
manage.py通过创建的配置识别PostgreSQL服务器
dev_henrique_desktop.py
from .base import *
DEBUG = True
# Allow specific host headers only
ALLOWED_HOSTS = ['localhost', '127.0.0.1', '.proregatta.com','10.0.2.2']
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'proregatta',
'USER': 'postgres',
'PASSWORD': '*****',
'HOST': 'localhost',
'PORT': '5432',
}
}
py和postgres都在PATH上
虚拟环境已激活
在安装psql时检查了pgAdmin III中超级用户创建的“ postgres”
然后开始问题
已经强制删除数据库
在迁移过程中搜索与“ api_role”相关的问题
在每个答案中,我都很关注。
每个人都说移民。何时无法进行初始移民
删除所有迁移和新的“ makemigrations”
取消安装并安装
问题仍然存在时格式化PC
我至少希望进行最初的移民 注意到其他计算机可能在数据库中缺少此关系,但在迁移中却没有。
Traceback (most recent call last):
File "C:\Users\henri\Documents\Projects\backend-django\venv\lib\site-packages\django\db\backends\utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
psycopg2.ProgrammingError: relation "api_role" does not exist
LINE 1: ...ECT "auth_group"."name", "auth_group"."name" FROM "api_role"...
^
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 "C:\Users\henri\Documents\Projects\backend-django\venv\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
utility.execute()
File "C:\Users\henri\Documents\Projects\backend-django\venv\lib\site-packages\django\core\management\__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\henri\Documents\Projects\backend-django\venv\lib\site-packages\django\core\management\base.py", line 316, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\henri\Documents\Projects\backend-django\venv\lib\site-packages\django\core\management\base.py", line 350, in execute
self.check()
File "C:\Users\henri\Documents\Projects\backend-django\venv\lib\site-packages\django\core\management\base.py", line 379, in check
include_deployment_checks=include_deployment_checks,
File "C:\Users\henri\Documents\Projects\backend-django\venv\lib\site-packages\django\core\management\commands\migrate.py", line 60, in _run_checks
issues.extend(super()._run_checks(**kwargs))
File "C:\Users\henri\Documents\Projects\backend-django\venv\lib\site-packages\django\core\management\base.py", line 366, in _run_checks
return checks.run_checks(**kwargs)
File "C:\Users\henri\Documents\Projects\backend-django\venv\lib\site-packages\django\core\checks\registry.py", line 71, in run_checks
new_errors = check(app_configs=app_configs)
File "C:\Users\henri\Documents\Projects\backend-django\venv\lib\site-packages\django\core\checks\urls.py", line 40, in check_url_namespaces_unique
all_namespaces = _load_all_namespaces(resolver)
File "C:\Users\henri\Documents\Projects\backend-django\venv\lib\site-packages\django\core\checks\urls.py", line 57, in _load_all_namespaces
url_patterns = getattr(resolver, 'url_patterns', [])
File "C:\Users\henri\Documents\Projects\backend-django\venv\lib\site-packages\django\utils\functional.py", line 37, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\henri\Documents\Projects\backend-django\venv\lib\site-packages\django\urls\resolvers.py", line 533, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "C:\Users\henri\Documents\Projects\backend-django\venv\lib\site-packages\django\utils\functional.py", line 37, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\henri\Documents\Projects\backend-django\venv\lib\site-packages\django\urls\resolvers.py", line 526, in urlconf_module
return import_module(self.urlconf_name)
File "C:\Users\henri\Documents\Projects\backend-django\venv\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 662, in exec_module
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
File "C:\Users\henri\Documents\Projects\backend-django\proregattaapi\urls.py", line 13, in <module>
from proregatta_admin import urls as proregatta_admin_urls
File "C:\Users\henri\Documents\Projects\backend-django\proregatta_admin\urls.py", line 4, in <module>
from .views import dashboard
File "C:\Users\henri\Documents\Projects\backend-django\proregatta_admin\views\dashboard.py", line 7, in <module>
from club_management.forms import SponsorForm
File "C:\Users\henri\Documents\Projects\backend-django\club_management\forms.py", line 1385, in <module>
class ManagerForm(forms.Form):
File "C:\Users\henri\Documents\Projects\backend-django\club_management\forms.py", line 1390, in ManagerForm
choices=Role.objects.all().order_by('name').values_list('name', 'name')
File "C:\Users\henri\Documents\Projects\backend-django\venv\lib\site-packages\django\forms\fields.py", line 768, in __init__
self.choices = choices
File "C:\Users\henri\Documents\Projects\backend-django\venv\lib\site-packages\django\forms\fields.py", line 785, in _set_choices
value = list(value)
File "C:\Users\henri\Documents\Projects\backend-django\venv\lib\site-packages\django\db\models\query.py", line 268, in __iter__
self._fetch_all()
File "C:\Users\henri\Documents\Projects\backend-django\venv\lib\site-packages\django\db\models\query.py", line 1183, in _fetch_all
self._result_cache = list(self._iterable_class(self))
File "C:\Users\henri\Documents\Projects\backend-django\venv\lib\site-packages\django\db\models\query.py", line 138, in __iter__
return compiler.results_iter(tuple_expected=True, chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
File "C:\Users\henri\Documents\Projects\backend-django\venv\lib\site-packages\django\db\models\sql\compiler.py", line 1013, in results_iter
results = self.execute_sql(MULTI, chunked_fetch=chunked_fetch, chunk_size=chunk_size)
File "C:\Users\henri\Documents\Projects\backend-django\venv\lib\site-packages\django\db\models\sql\compiler.py", line 1061, in execute_sql
cursor.execute(sql, params)
File "C:\Users\henri\Documents\Projects\backend-django\venv\lib\site-packages\django\db\backends\utils.py", line 100, in execute
return super().execute(sql, params)
File "C:\Users\henri\Documents\Projects\backend-django\venv\lib\site-packages\django\db\backends\utils.py", line 68, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "C:\Users\henri\Documents\Projects\backend-django\venv\lib\site-packages\django\db\backends\utils.py", line 77, in _execute_with_wrappers
return executor(sql, params, many, context)
File "C:\Users\henri\Documents\Projects\backend-django\venv\lib\site-packages\django\db\backends\utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
File "C:\Users\henri\Documents\Projects\backend-django\venv\lib\site-packages\django\db\utils.py", line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "C:\Users\henri\Documents\Projects\backend-django\venv\lib\site-packages\django\db\backends\utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: relation "api_role" does not exist
LINE 1: ...ECT "auth_group"."name", "auth_group"."name" FROM "api_role"...
^
答案 0 :(得分:1)
问题在这里:
File "C:\Users\henri\Documents\Projects\backend-django\club_management\forms.py", line 1390, in ManagerForm
choices=Role.objects.all().order_by('name').values_list('name', 'name')
当Django加载且数据库没有必填字段时,您进行查询
答案 1 :(得分:0)
我的一位合作者的答案:
有时候,当您在表单本身上查询数据库时,表单在迁移时会遇到问题。
如果您要对数据库中的任何内容进行伪造,请在 init
上执行此操作/关闭案例