title: Django: How do I get every table and all of that table's columns in a project?
body: <p>I'm creating a set of SQL full database copy scripts using MySQL's INTO OUTFILE and LOAD DATA LOCAL INFILE.</p>
  
  <p>Specifically:</p>
  
  <pre><code>SELECT {columns} FROM {table} INTO OUTFILE '{table}.csv'
  
  LOAD DATA LOCAL INFILE '{table}.csv' REPLACE INTO {table} {columns}
  </code></pre>
  
  <p>Because of this, I don't need just the tables, I also need the columns for the tables. </p>
  
  <p>I can get all of the tables and columns, but this doesn't include m2m tables:</p>
  
  <pre><code>from django.db.models import get_models()
  for model in get_models():
      table = model._meta.db_table
      columns = [field.column for field in model._meta.fields]
  </code></pre>
  
  <p>I can also get all of the tables, but this doesn't give me access to the columns:</p>
  
  <pre><code>from django.db import connection
  tables = connection.introspection.table_names()
  </code></pre>
  
  <p>How do you get every table and every corresponding column on that table for a Django project?</p>
  
  <p>More details: </p>
  
  <p>I'm doing this on a reasonably large dataset (>1GB) so using the <a href="http://dev.mysql.com/doc/refman/5.0/en/load-data.html" rel="nofollow noreferrer">flat file</a> method seems to be the only reasonable way to make this large of a copy in MySQL. I already have the schema copied over (using ./manage.py syncdb --migrate) and the issue I'm having is specifically with copying the data, which requires me to have the tables and columns to create proper SQL statements. Also, the reason I can't use default column ordering is because the production database I'm copying from has different column ordering than what is created with a fresh syncdb (due to many months worth of migrations and schema changes).</p>