Is there a way to run some custom SQL statements after syncdb does it thing creating the tables for the models? Specifically, I would like to create some database views.
在syncdb为模型创建表格之后,有没有办法运行一些自定义SQL语句?具体来说,我想创建一些数据库视图。
2 个解决方案
#1
4
Note: As mentioned in the comments, this method is deprecated as of Django 1.7.
注意:如评论中所述,自Django 1.7起,此方法已弃用。
Or just create a file called sql/<modelname>.sql: http://docs.djangoproject.com/en/dev/howto/initial-data/#providing-initial-sql-data
或者只创建一个名为sql /
#2
9
Yes, there are signals you can catch after a syncdb.
是的,有一些信号可以在syncdb之后捕获。
See management signals for docs.
请参阅docs的管理信号。
This is how the contrib.auth permissions table is populated, as well as the contenttypes framework table.
这是contrib.auth权限表的填充方式,以及contenttypes框架表。
#1
4
Note: As mentioned in the comments, this method is deprecated as of Django 1.7.
注意:如评论中所述,自Django 1.7起,此方法已弃用。
Or just create a file called sql/<modelname>.sql: http://docs.djangoproject.com/en/dev/howto/initial-data/#providing-initial-sql-data
或者只创建一个名为sql /
#2
9
Yes, there are signals you can catch after a syncdb.
是的,有一些信号可以在syncdb之后捕获。
See management signals for docs.
请参阅docs的管理信号。
This is how the contrib.auth permissions table is populated, as well as the contenttypes framework table.
这是contrib.auth权限表的填充方式,以及contenttypes框架表。