【问题标题】:Im trying to deploy my Django/ python project onto heroku.com我试图将我的 Django/python 项目部署到 heroku.com
【发布时间】:2021-03-09 22:47:36
【问题描述】:

该应用程序在本地主机上运行良好,但是当我登录我的网站或尝试创建帐户时,它给了我这个错误。

Request Method: POST
Request URL: <My Project>

环境:

    Django Version: 3.1.3
    Python Version: 3.8.6
    Installed Applications:
    ['learning_logs',
     'users',
     'bootstrap4',
     'django.contrib.admin',
     'django.contrib.auth',
     'django.contrib.contenttypes',
     'django.contrib.sessions',
     'django.contrib.messages',
     'django.contrib.staticfiles']
    Installed Middleware:
    ('whitenoise.middleware.WhiteNoiseMiddleware',
     'django.middleware.security.SecurityMiddleware',
     'django.contrib.sessions.middleware.SessionMiddleware',
     'django.middleware.common.CommonMiddleware',
     'django.middleware.csrf.CsrfViewMiddleware',
     'django.contrib.auth.middleware.AuthenticationMiddleware',
     'django.contrib.messages.middleware.MessageMiddleware',
     'django.middleware.clickjacking.XFrameOptionsMiddleware')

追溯

Traceback (most recent call last):
  File "/app/.heroku/python/lib/python3.8/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)

    The above exception (relation "auth_user" does not exist
    LINE 1: ...user"."is_active", "auth_user"."date_joined" FROM "auth_user...
                                                                 ^
    ) was the direct cause of the following exception:
      File "/app/.heroku/python/lib/python3.8/site-packages/django/core/handlers/exception.py", line 47, in inner
        response = get_response(request)
      File "/app/.heroku/python/lib/python3.8/site-packages/django/core/handlers/base.py", line 179, in _get_response
        response = wrapped_callback(request, *callback_args, **callback_kwargs)
      File "/app/.heroku/python/lib/python3.8/site-packages/django/views/generic/base.py", line 70, in view
        return self.dispatch(request, *args, **kwargs)
      File "/app/.heroku/python/lib/python3.8/site-packages/django/utils/decorators.py", line 43, in _wrapper
        return bound_method(*args, **kwargs)
      File "/app/.heroku/python/lib/python3.8/site-packages/django/views/decorators/debug.py", line 89, in sensitive_post_parameters_wrapper
        return view(request, *args, **kwargs)
      File "/app/.heroku/python/lib/python3.8/site-packages/django/utils/decorators.py", line 43, in _wrapper
        return bound_method(*args, **kwargs)
      File "/app/.heroku/python/lib/python3.8/site-packages/django/utils/decorators.py", line 130, in _wrapped_view
        response = view_func(request, *args, **kwargs)
      File "/app/.heroku/python/lib/python3.8/site-packages/django/utils/decorators.py", line 43, in _wrapper
        return bound_method(*args, **kwargs)
      File "/app/.heroku/python/lib/python3.8/site-packages/django/views/decorators/cache.py", line 44, in _wrapped_view_func
        response = view_func(request, *args, **kwargs)
      File "/app/.heroku/python/lib/python3.8/site-packages/django/contrib/auth/views.py", line 63, in dispatch
        return super().dispatch(request, *args, **kwargs)
      File "/app/.heroku/python/lib/python3.8/site-packages/django/views/generic/base.py", line 98, in dispatch
        return handler(request, *args, **kwargs)
      File "/app/.heroku/python/lib/python3.8/site-packages/django/views/generic/edit.py", line 141, in post
        if form.is_valid():
      File "/app/.heroku/python/lib/python3.8/site-packages/django/forms/forms.py", line 177, in is_valid
        return self.is_bound and not self.errors
      File "/app/.heroku/python/lib/python3.8/site-packages/django/forms/forms.py", line 172, in errors
        self.full_clean()
      File "/app/.heroku/python/lib/python3.8/site-packages/django/forms/forms.py", line 375, in full_clean
        self._clean_form()
      File "/app/.heroku/python/lib/python3.8/site-packages/django/forms/forms.py", line 402, in _clean_form
        cleaned_data = self.clean()
      File "/app/.heroku/python/lib/python3.8/site-packages/django/contrib/auth/forms.py", line 215, in clean
        self.user_cache = authenticate(self.request, username=username, password=password)
      File "/app/.heroku/python/lib/python3.8/site-packages/django/contrib/auth/__init__.py", line 73, in authenticate
        user = backend.authenticate(request, **credentials)
      File "/app/.heroku/python/lib/python3.8/site-packages/django/contrib/auth/backends.py", line 42, in authenticate
        user = UserModel._default_manager.get_by_natural_key(username)
      File "/app/.heroku/python/lib/python3.8/site-packages/django/contrib/auth/base_user.py", line 45, in get_by_natural_key
        return self.get(**{self.model.USERNAME_FIELD: username})
      File "/app/.heroku/python/lib/python3.8/site-packages/django/db/models/manager.py", line 85, in manager_method
        return getattr(self.get_queryset(), name)(*args, **kwargs)
      File "/app/.heroku/python/lib/python3.8/site-packages/django/db/models/query.py", line 425, in get
        num = len(clone)
      File "/app/.heroku/python/lib/python3.8/site-packages/django/db/models/query.py", line 269, in __len__
        self._fetch_all()
      File "/app/.heroku/python/lib/python3.8/site-packages/django/db/models/query.py", line 1308, in _fetch_all
        self._result_cache = list(self._iterable_class(self))
      File "/app/.heroku/python/lib/python3.8/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 "/app/.heroku/python/lib/python3.8/site-packages/django/db/models/sql/compiler.py", line 1156, in execute_sql
        cursor.execute(sql, params)
      File "/app/.heroku/python/lib/python3.8/site-packages/django/db/backends/utils.py", line 98, in execute
        return super().execute(sql, params)
      File "/app/.heroku/python/lib/python3.8/site-packages/django/db/backends/utils.py", line 66, in execute
        return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
      File "/app/.heroku/python/lib/python3.8/site-packages/django/db/backends/utils.py", line 75, in _execute_with_wrappers
        return executor(sql, params, many, context)
      File "/app/.heroku/python/lib/python3.8/site-packages/django/db/backends/utils.py", line 84, in _execute
        return self.cursor.execute(sql, params)
      File "/app/.heroku/python/lib/python3.8/site-packages/django/db/utils.py", line 90, in __exit__
        raise dj_exc_value.with_traceback(traceback) from exc_value
      File "/app/.heroku/python/lib/python3.8/site-packages/django/db/backends/utils.py", line 84, in _execute
        return self.cursor.execute(sql, params)
    
    Exception Type: ProgrammingError at /users/login/
    Exception Value: relation "auth_user" does not exist
    LINE 1: ...user"."is_active", "auth_user"."date_joined" FROM "auth_user...
                                                             ^

如果我还需要提供其他文件,请告诉我。

【问题讨论】:

  • 您能提供更多细节吗?

标签: python python-3.x django heroku


【解决方案1】:

您似乎没有在 Heroku 上运行迁移命令。

heroku run python manage.py migrate

这是一个example,用于在 Heroku 上部署 Django 项目。

【讨论】:

    猜你喜欢
    • 2020-10-18
    • 2012-11-13
    • 2016-01-11
    • 2020-10-24
    • 1970-01-01
    • 1970-01-01
    • 2014-05-09
    • 2020-04-28
    • 1970-01-01
    相关资源
    最近更新 更多