views:

166

answers:

2

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.

Thanks in advanced.

+4  A: 

Yes, there are signals you can catch after a syncdb.

See management signals for docs.

This is how the contrib.auth permissions table is populated, as well as the contenttypes framework table.

Van Gale
+4  A: 

Or just create a file called sql/<modelname>.sql: http://docs.djangoproject.com/en/dev/howto/initial-data/#providing-initial-sql-data

Dave
This works nicely enough, but the entire "custom SQL" feature has been termed a "hack" by one of the core developers, and a preference was expressed for using the post_syncdb signal. Can't find link at the moment. In any case it's guaranteed to stick around until 2.0, so no worries.
Carl Meyer