从sqlite迁移到postgresql数据库 - Django

时间:2018-06-11 20:10:46

标签: django postgresql

我正在尝试迁移到django中的postgresql数据库,以复制将要迁移到的生产环境。

我想我已经设置了postgresql数据库OK - 并将django中的设置文件更改为以下内容:

DATABASES = {
'default': {
    'ENGINE': 'django.db.backends.postgresql',
    'NAME': 'teamexchange',
    'USER': 'oliver',
    'PASSWORD': '',
    'HOST': '127.0.0.1',
    'PORT': '',
}
}

但是当我尝试使用manage.py来迁移表和重新上载数据时

e.g:

python3 manage.py migrate --run-syncdb

我收到以下错误:

Traceback (most recent call last):
  File "/Users/olivermonaghan-coombs/.virtualenvs/my_django_environment/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
    return self.cursor.execute(sql, params)
psycopg2.ProgrammingError: relation "teamapp_team" does not exist
LINE 1: SELECT "teamapp_team"."team_code" FROM "teamapp_team"
                                               ^


The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "manage.py", line 15, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/olivermonaghan-coombs/.virtualenvs/my_django_environment/lib/python3.6/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line
    utility.execute()
  File "/Users/olivermonaghan-coombs/.virtualenvs/my_django_environment/lib/python3.6/site-packages/django/core/management/__init__.py", line 347, in execute
    django.setup()
  File "/Users/olivermonaghan-coombs/.virtualenvs/my_django_environment/lib/python3.6/site-packages/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/Users/olivermonaghan-coombs/.virtualenvs/my_django_environment/lib/python3.6/site-packages/django/apps/registry.py", line 112, in populate
    app_config.import_models()
  File "/Users/olivermonaghan-coombs/.virtualenvs/my_django_environment/lib/python3.6/site-packages/django/apps/config.py", line 198, in import_models
    self.models_module = import_module(models_module_name)
  File "/Users/olivermonaghan-coombs/.virtualenvs/my_django_environment/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 "/Users/olivermonaghan-coombs/teamexchange/teamapp/models.py", line 266, in <module>
    class Fixture(models.Model):
  File "/Users/olivermonaghan-coombs/teamexchange/teamapp/models.py", line 289, in Fixture
    team_choices = tuple((x['team_code'], x['team_code']) for x in Team.objects.all().values('team_code'))
  File "/Users/olivermonaghan-coombs/.virtualenvs/my_django_environment/lib/python3.6/site-packages/django/db/models/query.py", line 272, in __iter__
    self._fetch_all()
  File "/Users/olivermonaghan-coombs/.virtualenvs/my_django_environment/lib/python3.6/site-packages/django/db/models/query.py", line 1179, in _fetch_all
    self._result_cache = list(self._iterable_class(self))
  File "/Users/olivermonaghan-coombs/.virtualenvs/my_django_environment/lib/python3.6/site-packages/django/db/models/query.py", line 106, in __iter__
    for row in compiler.results_iter(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size):
  File "/Users/olivermonaghan-coombs/.virtualenvs/my_django_environment/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 1017, in results_iter
    results = self.execute_sql(MULTI, chunked_fetch=chunked_fetch, chunk_size=chunk_size)
  File "/Users/olivermonaghan-coombs/.virtualenvs/my_django_environment/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 1066, in execute_sql
    cursor.execute(sql, params)
  File "/Users/olivermonaghan-coombs/.virtualenvs/my_django_environment/lib/python3.6/site-packages/django/db/backends/utils.py", line 100, in execute
    return super().execute(sql, params)
  File "/Users/olivermonaghan-coombs/.virtualenvs/my_django_environment/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 "/Users/olivermonaghan-coombs/.virtualenvs/my_django_environment/lib/python3.6/site-packages/django/db/backends/utils.py", line 77, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/Users/olivermonaghan-coombs/.virtualenvs/my_django_environment/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
    return self.cursor.execute(sql, params)
  File "/Users/olivermonaghan-coombs/.virtualenvs/my_django_environment/lib/python3.6/site-packages/django/db/utils.py", line 89, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/Users/olivermonaghan-coombs/.virtualenvs/my_django_environment/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 "teamapp_team" does not exist
LINE 1: SELECT "teamapp_team"."team_code" FROM "teamapp_team"

我试过了:

  • 更改设置文件中的HOST变量(使用port和as localhost)
  • 从迁移中删除所有迁移文件
  • 删除应用周围的所有.pyc文件

但我仍然得到同样的错误。

任何帮助非常感谢

0 个答案:

没有答案