【问题标题】:PyCharm discovering new core Django (rather than app) manage.py tasks?PyCharm 发现新的核心 Django(而不是应用程序)manage.py 任务?
【发布时间】:2014-01-21 04:13:40
【问题描述】:

我希望在 PyCharm 2.7.3 中使用更新的 Django (1.7.dev)...所以它是我项目的 virtualenv 中安装的唯一 Django 版本。

但是,“工具”->“运行 manage.py 任务”列表并没有发现 Django 本身包含的新命令,例如 migratemakemigrations。 (根据之前使用 South 等应用程序的经验,我希望所有可用的任务都会被自动发现。)

有没有办法帮助 PyCharm 2.7.3 发现和使用这些新选项?

【问题讨论】:

  • 更新:还没有学会让这些命令出现在 PyCharm“运行 manage.py 任务”列表中的方法。当然可以在 PyCharm 外部运行它们,也可以将它们添加为自定义“运行/调试配置”,以便在 PyCharm 内部交替执行。我还没有遇到在 PyCharm 2.7.3 中使用 Django 1.7.dev 的任何其他障碍。我怀疑“运行 manage.py 任务”列表是 [hardcoded-options + app-autodiscoveries],而不是 [autodiscovered-built-ins + app-autodiscoveries],因为该列表仍然包含选项(如 cleanup) Django 1.7.dev.

标签: python django pycharm


【解决方案1】:

“工具”->“运行 manage.py 任务”看不到 makemigration 或 migrate 参数。

您可以通过右键单击项目中的 manage.py 文件来运行 manage.py。

这个输出:

*

*Usage: manage.py subcommand [options] [args]
Options:
  -v VERBOSITY, --verbosity=VERBOSITY
                        Verbosity level; 0=minimal output, 1=normal output,
                        2=verbose output, 3=very verbose output
  --settings=SETTINGS   The Python path to a settings module, e.g.
                        "myproject.settings.main". If this isn't provided, the
                        DJANGO_SETTINGS_MODULE environment variable will be
                        used.
  --pythonpath=PYTHONPATH
                        A directory to add to the Python path, e.g.
                        "/home/djangoprojects/myproject".
  --traceback           Raise on exception
  --no-color            Don't colorize the command output.
  --version             show program's version number and exit
  -h, --help            show this help message and exit
Type 'manage.py help <subcommand>' for help on a specific subcommand.
Available subcommands:
[auth]
    changepassword
    createsuperuser
[django]
    check
    compilemessages
    createcachetable
    dbshell
    diffsettings
    dumpdata
    flush
    inspectdb
    loaddata
    makemessages
    makemigrations
    migrate
    runfcgi
    shell
    sql
    sqlall
    sqlclear
    sqlcustom
    sqldropindexes
    sqlflush
    sqlindexes
    sqlinitialdata
    sqlmigrate
    sqlsequencereset
    squashmigrations
    startapp
    startproject
    syncdb
    test
    testserver
    validate
[sessions]
    clearsessions
[staticfiles]
    collectstatic
    findstatic
    runserver*

*

如您所见,“makemigrations”和“migrate”在 django 的可用子命令中

所以你必须“运行”->“编辑配置”并在脚本参数中添加“makemigrations”或“migrate”

现在运行脚本,它可以工作了

【讨论】:

    【解决方案2】:

    这很可能是因为您在 INSTALLED_APPS 元组中添加了应用程序。所以如果是这样的:

    INSTALLED_APPS = (
        'django.contrib.auth',
        'django.contrib.contenttypes',
        'django.contrib.sessions',
        'django.contrib.sites',
        'django.contrib.messages',
        'django.contrib.staticfiles',
        # Uncomment the next line to enable the admin:
        'django.contrib.admin',
        # Third Party apps -------------------------------------->
        'south',
        'django_extensions',
        'dajaxice',
        'dajax',
        # My apps ----------------------------------------------->
        'blog',
    )
    

    那么应该没有问题,你应该能够找到你要找的命令,如果没有,那么你有一个错误。但是,如果您将事情安排成这样:

    DJANGO_APPS = (
        'django.contrib.auth',
        'django.contrib.contenttypes',
        'django.contrib.sessions',
        'django.contrib.sites',
        'django.contrib.messages',
        'django.contrib.staticfiles')
    
    THIRD_PARTY_APPS = (
        'south',
        'django_extensions',
        'dajaxice',
        'dajax',
    )
    
    MY_APPS = ('blog', )
    
    INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + MY_APPS
    

    那么你有一个问题,2.7 因为 PyCharm 无法理解这一点。所以,我的建议是你按照我开始时向你展示的方式制作元组。

    【讨论】:

    • 唉,不是这样的。我没有以这种方式连接 INSTALLED_APPS 列表。此外,像makemigrations 这样找不到的命令不是来自应用程序;它们是 Django 1.7.dev 本身的一部分。 (例如在https://github.com/django/django/tree/master/django/core/management/commands 中查看它们。)
    • @gojomo 那这是因为2.7只支持到1.5,1.7进来3。
    • PyCharm 3.0.1 已经发布,其文档仅声称对 Django 1.5 的正式支持。尽管如此,通常可以在 PyCharm 中使用更高版本的 Django,并且应用程序中的 autodiscovery-of-commands-in-apps 表明也有可能发现内置插件。所以仍然希望在这里找到实际限制或可能的解决方法的线索。
    猜你喜欢
    • 2023-03-20
    • 1970-01-01
    • 1970-01-01
    • 2019-01-12
    • 1970-01-01
    • 2019-09-10
    • 2020-07-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多