简体   繁体   中英

Python Django Unknown Command 'SQL'

I'm following this tutorial http://www.sitepoint.com/building-simple-rest-api-mobile-applications/

I'm trying to run SQL by

$ 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.

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.

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). Or write management commands for any clean up tasks.

Yes it is possible, using the inspectdb command:

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.

As Ignacio pointed out, there is a guide for your situation in the documentation.

Source : link

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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