迁移数据库从克隆的django项目到postgresql db有问题。
os是ubuntu服务器18.04
安装了python3-pip python3-dev libpq-dev postgresql postgresql-contrib nginx。
设置postgresql db,升级pip3,安装virtualenv,创建/ opt / projectdir。
在projectdir内部创建virtualenv moviesenv并激活它,用pip创建目录电影安装django,gunicorn和psycopg2,然后在目录电影内输入:git clone https://username/reponame。设置允许主机和数据库部分。键入manage.py makemigrations和recive错误消息psycopg2.ProgrammingError:关系“movie_movie”不存在django.db.utils.ProgrammingError:关系“movie_movie”不存在
这只是一小段错误输出,但我不想在这里粘贴。如果有人可以帮忙请。
好的,这里完整的追溯
Traceback (most recent call last):
File "/opt/myproject/myprojectenv/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
psycopg2.ProgrammingError: relation "movie_movie" does not exist
LINE 1: ...movie_movie"."plot", "movie_movie"."trailer" FROM "movie_mov...
^
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 "/opt/myproject/myprojectenv/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/opt/myproject/myprojectenv/lib/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/opt/myproject/myprojectenv/lib/python3.6/site-packages/django/core/management/base.py", line 316, in run_from_argv
self.execute(*args, **cmd_options)
File "/opt/myproject/myprojectenv/lib/python3.6/site-packages/django/core/management/base.py", line 350, in execute
self.check()
File "/opt/myproject/myprojectenv/lib/python3.6/site-packages/django/core/management/base.py", line 379, in check
include_deployment_checks=include_deployment_checks,
File "/opt/myproject/myprojectenv/lib/python3.6/site-packages/django/core/management/base.py", line 366, in _run_checks
return checks.run_checks(**kwargs)
File "/opt/myproject/myprojectenv/lib/python3.6/site-packages/django/core/checks/registry.py", line 71, in run_checks
new_errors = check(app_configs=app_configs)
File "/opt/myproject/myprojectenv/lib/python3.6/site-packages/django/core/checks/urls.py", line 13, in check_url_config
return check_resolver(resolver)
File "/opt/myproject/myprojectenv/lib/python3.6/site-packages/django/core/checks/urls.py", line 23, in check_resolver
return check_method()
File "/opt/myproject/myprojectenv/lib/python3.6/site-packages/django/urls/resolvers.py", line 396, in check
for pattern in self.url_patterns:
File "/opt/myproject/myprojectenv/lib/python3.6/site-packages/django/utils/functional.py", line 37, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/opt/myproject/myprojectenv/lib/python3.6/site-packages/django/urls/resolvers.py", line 533, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/opt/myproject/myprojectenv/lib/python3.6/site-packages/django/utils/functional.py", line 37, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/opt/myproject/myprojectenv/lib/python3.6/site-packages/django/urls/resolvers.py", line 526, in urlconf_module
return import_module(self.urlconf_name)
File "/opt/myproject/myprojectenv/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/opt/myproject/MovieHunter/MovieHunter/urls.py", line 19, in <module>
from . import views
File "/opt/myproject/MovieHunter/MovieHunter/views.py", line 6, in <module>
from movie.initializer import search_index
File "/opt/myproject/MovieHunter/movie/initializer.py", line 5, in <module>
search_index = Index()
File "/opt/myproject/MovieHunter/movie/search_index.py", line 12, in __init__
self.__load_data_from_db()
File "/opt/myproject/MovieHunter/movie/search_index.py", line 16, in __load_data_from_db
for movie in Movie.objects.all():
File "/opt/myproject/myprojectenv/lib/python3.6/site-packages/django/db/models/query.py", line 268, in __iter__
self._fetch_all()
File "/opt/myproject/myprojectenv/lib/python3.6/site-packages/django/db/models/query.py", line 1183, in _fetch_all
self._result_cache = list(self._iterable_class(self))
File "/opt/myproject/myprojectenv/lib/python3.6/site-packages/django/db/models/query.py", line 54, in __iter__
results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
File "/opt/myproject/myprojectenv/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 1061, in execute_sql
cursor.execute(sql, params)
File "/opt/myproject/myprojectenv/lib/python3.6/site-packages/django/db/backends/utils.py", line 100, in execute
return super().execute(sql, params)
File "/opt/myproject/myprojectenv/lib/python3.6/site-packages/django/db/backends/utils.py", line 68, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/opt/myproject/myprojectenv/lib/python3.6/site-packages/django/db/backends/utils.py", line 77, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/opt/myproject/myprojectenv/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
File "/opt/myproject/myprojectenv/lib/python3.6/site-packages/django/db/utils.py", line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/opt/myproject/myprojectenv/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: relation "movie_movie" does not exist
LINE 1: ...movie_movie"."plot", "movie_movie"."trailer" FROM "movie_mov...
正如@Alasdair所提到的,你想从一个不存在的表中进行查询似乎是一个查询问题。这是你可以尝试解决问题的related link。它发生在:
File "/opt/myproject/MovieHunter/movie/search_index.py", line 16, in __load_data_from_db
for movie in Movie.objects.all():