python 无法打开文件'manage.py'-“heroku 运行 python manage.py 迁移命令输入”

Posted

技术标签:

【中文标题】python 无法打开文件\'manage.py\'-“heroku 运行 python manage.py 迁移命令输入”【英文标题】:python cant open file 'manage.py' - "heroku run python manage.py migrate command input"python 无法打开文件'manage.py'-“heroku 运行 python manage.py 迁移命令输入” 【发布时间】:2021-05-23 00:42:46 【问题描述】:

您好,我已经完成了我的 Django pycharm 项目,现在正在尝试将其上传到 heroku/在 heroku 上托管。我已经关注了这个链接https://medium.com/@qazi/how-to-deploy-a-django-app-to-heroku-in-2018-the-easy-way-48a528d97f9c,过去它实际上已经成功地为我工作过。当我执行此步骤时,您是否将此命令放入了“heroku run python manage.py migrate”,但我继续收到此错误消息“正在运行 python manage.py migrate on ⬢ radiant-retreat-19016 ... 启动,运行。 6371(免费) python:无法打开文件'manage.py':[Errno 2]没有这样的文件或目录' 我不是一个初学者,所以我知道我的 manage.py 文件在正确的位置,尤其是因为我可以运行“python manage.py runserver”。我将把代码连同我的 manage.py 代码和设置一起附加到下面的 procFile 中。我在互联网上到处寻找这个问题,有些人有它,但没有任何东西对他们有用。如果您需要,我会附上任何其他代码。我什至将所有代码转移到了一个新项目中,并且出现了同样的问题。

web: gunicorn inspect_list2.wsgi






#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys


def main():
    """Run administrative tasks."""
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'inspect_list2.settings')
    try:
        from django.core.management import execute_from_command_line
    except ImportError as exc:
        raise ImportError(
            "Couldn't import Django. Are you sure it's installed and "
            "available on your PYTHONPATH environment variable? Did you "
            "forget to activate a virtual environment?"
        ) from exc
    execute_from_command_line(sys.argv)


if __name__ == '__main__':
    main()






"""
Django settings for inspect_list project.

Generated by 'django-admin startproject' using Django 2.2.14.

For more information on this file, see
https://docs.djangoproject.com/en/2.2/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.2/ref/settings/
"""

import os
import django_heroku

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
TEMPLATE_DIR = os.path.join(BASE_DIR, 'templates')


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'not showing this but its there'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'my_app',
    #'auth',

]

MIDDLEWARE = [
    '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',
]

ROOT_URLCONF = 'inspect_list2.urls'

TEMPLATES = [
    
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [TEMPLATE_DIR,],
        'DIRS': [os.path.join(BASE_DIR, 'templates')],
        'APP_DIRS': True,
        'OPTIONS': 
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        ,
    ,
]

WSGI_APPLICATION = 'inspect_list2.wsgi.application'


# Database
# https://docs.djangoproject.com/en/2.2/ref/settings/#databases

DATABASES = 
    'default': 
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    



# Password validation
# https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    ,
    
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    ,
    
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    ,
    
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    ,
]


# Internationalization
# https://docs.djangoproject.com/en/2.2/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, javascript, Images)
# https://docs.djangoproject.com/en/2.2/howto/static-files/

STATIC_URL = '/static/'
STATICFILES_DIRS = (os.path.join(BASE_DIR, 'static'),)

AUTH_USER_MODEL = 'my_app.CustomUser'

LOGIN_REDIRECT_URL = 'front_page'
LOGOUT_REDIRECT_URL = 'home'

django_heroku.settings(locals())

【问题讨论】:

您可以在settings.py 文件中设置数据库凭据并运行python manage.py migrate,而不是运行heroku 命令,这也适用于您? 【参考方案1】:

由此修复

heroku run python **FOLDER**/manage.py migrate

heroku run python HOME/manage.py migrate

【讨论】:

谢谢。较旧的答案都告诉人们修改他们的 wsgi 文件和其他东西。这更有意义。【参考方案2】:

我终于在 10 小时后弄明白了。其他在线消息来源是正确的。如果您参考我在最底部命令中发布的链接。如果你比最后一个命令先运行 git push 东西,然后运行 ​​heroku migrate 命令,它应该可以工作。等待!如果它不起作用,那么如果你触及了你的 git 存储库的东西或更改了名称或弄乱了你的 squilte3 文件并且你不知道你在做什么然后将你的所有代码转移到另一个项目中,这样 git 的东西和 squilte3 的东西自动进行并重置,然后再次按照此评论中的说明进行操作。如果不是,我不知道该告诉你什么,但它对我有用。

【讨论】:

以上是关于python 无法打开文件'manage.py'-“heroku 运行 python manage.py 迁移命令输入”的主要内容,如果未能解决你的问题,请参考以下文章

Django manage.py runserver无法打开浏览器

无法运行 python manage.py rusnerver

关于Django无法启动数据库和无法命令行启动manage.py的解决方法

python manage.py shell 不再打开:NameError: name 'Posts' is not defined

Django 无法导入本地设置

Django 中 python manage.py makemigrations 与 python manage.py migrate