In django, how do I call the subcommand 'syncdb' from the initialization script?

前端 未结 5 2020
故里飘歌
故里飘歌 2020-12-04 16:42

I\'m new to python and django, and when following the Django Book I learned about the command \'python manage.py syncdb\' which generated database tables for me. In developm

5条回答
  •  感动是毒
    2020-12-04 17:25

    Update

    I added a script called run.sh in the project's root directory. This worked for me with an SQLite database:

    #!/usr/bin/python
    from django.core.management import call_command
    call_command('syncdb')
    call_command('runserver')
    

    Original Answer

    I am not sure I understand what you mean by "scripting the syncdb command". You usually execute python manage.py syncdb from the command line. This is usually done after adding new models. In case you want to you easily accomplish this using a simple shell script. I don't see any reason to place (or invoke) syncdb from within settings.py.

    Could you add more details to your question? Add context and explain what exactly are you trying to get done?

提交回复
热议问题