执行makemigrations时不存在关系

时间:2017-06-07 12:53:59

标签: python django postgresql amazon-ec2

我正在使用Postgres和Django。 我将localhost上的服务器更改为Amazon EC2。

然而,当我去'python manage.py makemigrations'或'python manage.py makemigrations myapp'时,我出现了以下错误: Relation [table_name]不存在。

数据库中不会创建关系/表。

Settings.py:

INSTALLED_APPS = [
'myapp',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
]
DATABASES = {
'default': {
    'ENGINE': 'django.db.backends.postgresql_psycopg2',
    'NAME': 'freguesia',
    'USER': 'postgres',
    'PASSWORD': 'xxxxx',
    'HOST': 'localhost',
    'PORT': '',
}

}

错误:

  
    

追踪(最近一次通话):       文件“/usr/local/lib/python3.5/dist-packages/django/db/backends/utils.py”,第65行,执行         return self.cursor.execute(sql,params)     psycopg2.ProgrammingError:关系“myapp_servico”不存在     第1行:......“myapp_servico”。“id”,“myapp_servico”。“nome”FROM“myapp_ser ...                                                                  ^

  
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 363, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python3.5/dist-packages/django/core/management/__init__.py", line 355, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python3.5/dist-packages/django/core/management/base.py", line 283, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/local/lib/python3.5/dist-packages/django/core/management/base.py", line 327, in execute
    self.check()
  File "/usr/local/lib/python3.5/dist-packages/django/core/management/base.py", line 359, in check
    include_deployment_checks=include_deployment_checks,
  File "/usr/local/lib/python3.5/dist-packages/django/core/management/commands/migrate.py", line 62, in _run_checks
    issues.extend(super(Command, self)._run_checks(**kwargs))
  File "/usr/local/lib/python3.5/dist-packages/django/core/management/base.py", line 346, in _run_checks
    return checks.run_checks(**kwargs)
  File "/usr/local/lib/python3.5/dist-packages/django/core/checks/registry.py", line 81, in run_checks
    new_errors = check(app_configs=app_configs)
  File "/usr/local/lib/python3.5/dist-packages/django/core/checks/urls.py", line 16, in check_url_config
    return check_resolver(resolver)
  File "/usr/local/lib/python3.5/dist-packages/django/core/checks/urls.py", line 26, in check_resolver
    return check_method()
  File "/usr/local/lib/python3.5/dist-packages/django/urls/resolvers.py", line 254, in check
    for pattern in self.url_patterns:
  File "/usr/local/lib/python3.5/dist-packages/django/utils/functional.py", line 35, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/usr/local/lib/python3.5/dist-packages/django/urls/resolvers.py", line 405, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "/usr/local/lib/python3.5/dist-packages/django/utils/functional.py", line 35, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/usr/local/lib/python3.5/dist-packages/django/urls/resolvers.py", line 398, in urlconf_module
    return import_module(self.urlconf_name)
  File "/usr/lib/python3.5/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 665, in exec_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "/home/ubuntu/PortalJunta/PortalJunta/urls.py", line 18, in <module>
    from myapp import views
  File "/home/ubuntu/PortalJunta/myapp/views.py", line 4, in <module>
    from myapp.forms import *
  File "/home/ubuntu/PortalJunta/myapp/forms.py", line 145, in <module>
    class RequerimentoForm(forms.ModelForm):
  File "/home/ubuntu/PortalJunta/myapp/forms.py", line 157, in RequerimentoForm
    servico = forms.MultipleChoiceField(widget=forms.SelectMultiple, choices=opcoes)
  File "/usr/local/lib/python3.5/dist-packages/django/forms/fields.py", line 779, in __init__
    self.choices = choices
  File "/usr/local/lib/python3.5/dist-packages/django/forms/fields.py", line 796, in _set_choices
    value = list(value)
  File "/usr/local/lib/python3.5/dist-packages/django/db/models/query.py", line 250, in __iter__
    self._fetch_all()
  File "/usr/local/lib/python3.5/dist-packages/django/db/models/query.py", line 1103, in _fetch_all
    self._result_cache = list(self._iterable_class(self))
  File "/usr/local/lib/python3.5/dist-packages/django/db/models/query.py", line 122, in __iter__
    for row in compiler.results_iter():
  File "/usr/local/lib/python3.5/dist-packages/django/db/models/sql/compiler.py", line 828, in results_iter
    results = self.execute_sql(MULTI)
  File "/usr/local/lib/python3.5/dist-packages/django/db/models/sql/compiler.py", line 886, in execute_sql
    raise original_exception
  File "/usr/local/lib/python3.5/dist-packages/django/db/models/sql/compiler.py", line 876, in execute_sql
    cursor.execute(sql, params)
  File "/usr/local/lib/python3.5/dist-packages/django/db/backends/utils.py", line 80, in execute
    return super(CursorDebugWrapper, self).execute(sql, params)
  File "/usr/local/lib/python3.5/dist-packages/django/db/backends/utils.py", line 65, 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 65, in execute
    return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: relation "myapp_servico" does not exist
LINE 1: ..."myapp_servico"."id", "myapp_servico"."nome" FROM "myapp_ser...

你能帮助我吗?

0 个答案:

没有答案