简体   繁体   English

Django(pre1.7)管理命令来为应用程序运行customsql

[英]Django (pre1.7) management command to run the customsql for an app

Django (pre 1.7 and pre-the new migration functionality), has a management command sqlcustom to display the custom SQL that would be run for an app. Django(1.7之前的版本和新的迁移功能之前的版本)具有管理命令sqlcustom显示将为应用程序运行的自定义SQL。 However that prints it to the terminal. 但是,这会将其打印到终端。 Is there any single django management command to actually run all the migrations? 是否有任何django管理命令可以实际运行所有迁移?

I'm using a Django pre1.7 project which uses South for migrations, and we have some custom SQL (for sql views), and I want to have all the database stuff done via migrations. 我正在使用一个使用South进行迁移的Django pre1.7项目,并且我们有一些自定义SQL(用于sql视图),并且我想通过迁移完成所有数据库工作。 Custom SQL is loaded by syncdb on vanilla Django, but when you use South, it overrides syncdb and doesn't run custom sql. 自定义SQL是由syncdb Django上的syncdb加载的,但是当您使用South时,它将覆盖syncdb并且不会运行自定义sql。 I'd like to create a South migration for an app that is really simple and calls this management command to load the custom SQL. 我想为一个非常简单的应用程序创建一个向南迁移,并调用此管理命令来加载自定义SQL。 (You can call django management commands from inside python ). (您可以从python内部调用django管理命令 )。 I don't want to duplicate the SQL inside the migration. 我不想在迁移中复制SQL。

You can pipe the output of sqlcustom to dbshell . 您可以将sqlcustom的输出通过管道sqlcustomdbshell Something like this: 像这样:

django-admin.py sqlcustom myapp > django-admin.py dbshell

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

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