I am exploring Django with MySQL & have a few things that I wanted to discuss –
- How can I add an index (on some field)? Can I do it through the Django Model Layer?
- If I want to migrate some old data into these new DB tables/models, will I have to write some script myself or does Django provide schema to schema mapping tools?
- If I need to change the schema for the existing Django Models, then what’s the easiest way to do this? I know this depends on my schema but is it as simple as create a new column & run
python manage.py syncdb? - Lastly how do I profile MySQL db of all the queries I run from Django Models? I am looking for something like
DEBUG=True and TEMPLATE_DEBUG=Truekind of solution, where I’ll get the query performance (runtime etc.) on the browser.
Thanks in advance…
You can. Take a look at the
Field.db_indexoption.Django does not have a built in tool to do data migration. For migrating existing data you will have to write a custom script. This may be possible using an external migration tool (such as South, see below) but I haven’t tried it.
Use a migration tool. South is one of the popular and effective ones out there. There are others too. Using a tool will make your life much more easier for many reasons. For e.g.
syncdbwill not add new columns, only new tables.One of the ways to accomplish this is to use this classic Django snippet. Using the snippet you can append statistics about the queries fired to render a page to the bottom of the page if
DEBUGis set.Update
Another way to display the debug information is to use the django-debug-toolbar. Thanks @diegueus9.