Is it safe to write your own table creation SQL for use with Django, when the generated tables are not enough?
I need to have some references in my table开发者_如何学C and a bunch of "deferrable initially deferred" modifiers, but I can't find a way to make this work in the default generated Django code.
Is it safe to create the table manually and still use Django models?
Yes.
I don't see why not, but that would be most unconventional and breaking convention usually leads to complications down the track.
Describe the problem you think it will solve and perhaps someone can offer a more conventional solution.
Yep! Django is super flexible in this regard. It even has a really neat built-in management command, inspectdb, which can do a fairly good job automatically generating your models from an existing database (really great for integrating django with legacy code, but might be suitable here too, to doublecheck your models match up).
If you are going to use custom SQL, you could do it in the context of Django South, so that down the line you will treat subsequent changes in the context of transformations / migrations (which hopefully means you will be mindful/careful in future changes).
Alternatively, without using additional apps, you could use the post-syncdb signal to define custom SQL in the form of UPDATEs
精彩评论