What's the best way to deploy custom SQL for views used by unmanaged Django models?
I have a model myapp.models.MyModel using a view myview.sql, specified in the models "db_table" meta attribute. So, following the docs, I placed the custom SQL file in myapp/sql/myview.sql.
However, after I run python manage.py syncdb
, the view is not installed. Running sqlcustom similarly does not show the view.
What else do I need to do so Django will automatically detect and deploy my custom SQL?
python manage.py sqlcustom
will only output the custom SQL statements that you've defined, but you need to execute them in the database. Of course, you can copy and paste, but if you want to automate the process and have it be less tedious/error-prone, one easy way to do so (at least on a *nix environment) is to use a pipe:
python manage.py sqlcustom myapp | python manage.py dbshell
According to the doc, name the file myapp/sql/mymodel.sql instead of myapp/sql/myview.sql
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With