简体   繁体   English

Python Django未知命令'SQL'

[英]Python Django Unknown Command 'SQL'

I'm following this tutorial http://www.sitepoint.com/building-simple-rest-api-mobile-applications/ 我正在关注本教程http://www.sitepoint.com/building-simple-rest-api-mobile-applications/

I'm trying to run SQL by 我正在尝试运行SQL

$ python manage.py sql fishes

However it says 然而它说

Unknown Command: 'sql'

If I type 如果我输入

$ python manage.py help

I get this, and SQL doesn't appear in the list. 我明白了,SQL没有出现在列表中。

Available subcommands:

[auth]
    changepassword
    createsuperuser

[django]
    check
    compilemessages
    createcachetable
    dbshell
    diffsettings
    dumpdata
    flush
    inspectdb
    loaddata
    makemessages
    makemigrations
    migrate
    sendtestemail
    shell
    showmigrations
    sqlflush
    sqlmigrate
    sqlsequencereset
    squashmigrations
    startapp
    startproject
    test
    testserver

[sessions]
    clearsessions

[staticfiles]
    collectstatic
    findstatic
    runserver

Unfortunately that doesn't exist any more, however the command manage.py dbshell does. 不幸的是,这不再存在,但是命令manage.py dbshell

Generally speaking however, you should try to use models, with load_data etc to preserve the data integrity (as validations etc may happen in models rather then relying on underlying data bits). 但是,一般来说,您应该尝试使用load_data等模型来保持数据的完整性(因为验证等可能在模型中发生,而不是依赖于底层数据位)。 Or write management commands for any clean up tasks. 或者为任何清理任务编写管理命令。

Yes it is possible, using the inspectdb command: 是的,可以使用inspectdb命令:

python manage.py inspectdb

or 要么

python manage.py inspectdb > models.py

to get them in into the file 让他们进入文件

This will look at the database configured in your settings.py and outputs model classes to standard output. 这将查看settings.py配置的数据库,并将模型类输出到标准输出。

As Ignacio pointed out, there is a guide for your situation in the documentation. 正如Ignacio指出的那样,文档中提供了有关您的情况指南

Source : link 来源: 链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM