Switching database backend in Mezzanine
<p>I am trying to script a series of examples where the reader incrementally builds a web application. The first stage takes place with Mezzanine's default configuration, using built-in SQLlite:</p>

<pre><code>sudo pip install mezzanine
sudo -u mezzanine python manage.py createdb 
</code></pre>

<p>After the initial examples are complete, I want to switch the existing setup to a mysql backend. If that is too complex, I at least want to re-create the built-in examples that come with Mezzanine on the new backend, but Mezzanine won't allow re-running <code>createdb</code></p>

<pre><code>CommandError: Database already created, you probably want the migrate command
</code></pre>

<p>This seems like something that should be incredibly simple, yet I can't seem to get it quite right (and <code>migrate</code> alone does not do the trick). Google and official docs not helping either.</p>

<p>Steps I am taking: first, I create a MySQL database on Amazon RDS. Then, I set appropriate configuration for it in myapp/local_settings (I am sure these steps are correct). Then:</p>

<pre><code>sudo apt install python-mysqldb
sudo -u mezzanine python /srv/mezzanine/manage.py migrate
</code></pre>

<p>but then:</p>

<pre><code>Running migrations:
   No migrations to apply.
</code></pre>

<p>What am I missing?</p>

<p>The Mezzanine project is based on Django, the Python framework.<br>
Unless you encounter a Mezzanine specific problem, most issues can be solved by figuring out how its done the Django way.</p>

<p><em>Migrations</em> is just Django's way of refering to alterations &amp; amendments <em>within</em> the DB, ie, the schema (because apps evolve &amp; databases are metamorphic).</p>

<p>In order to actually migrate the data however you could:</p>

<ol>
<li><p><strong>Export the contents from the current database, eg:</strong></p>

<p>./manage.py dumpdata > db-dump-in-json.json<br>
./manage.py --format=xml > db-dump-in-xml.xml</p></li>
</ol>

<p>This may crash if there is too much data or not enough memory. Then the thing would be to use native DB tools to get the <em>dump</em>.</p>

<ol start="2">
<li><p><strong>Create and add the settings for the new DB in <code>settings.py</code>:</strong></p></li>
<li><p><strong>Create the tables and set them up (based on your <em>models</em>) on the newly defined DB:</strong></p>

<p>./manage.py makemigrations<br>
./manage.py migrate</p></li>
</ol>

<p><code>createdb</code> = <code>syncdb</code> (create) + <code>migrate</code> (set) combined </p>

<ol start="4">
<li><p><strong>And reload the exported data there:</strong></p>

<p>./manage.py loaddata db-dump-in-json.json</p></li>
</ol>

python mysql django mezzanine