Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>To answer your first question, the simple model/table rename is pretty straightforward. Run the command:</p> <pre><code>./manage.py schemamigration yourapp rename_foo_to_bar --empty </code></pre> <p>(Update 2: try <code>--auto</code> instead of <code>--empty</code> to avoid the warning below. Thanks to @KFB for the tip.)</p> <p>If you're using an older version of south, you'll need <code>startmigration</code> instead of <code>schemamigration</code>.</p> <p>Then manually edit the migration file to look like this:</p> <pre><code>class Migration(SchemaMigration): def forwards(self, orm): db.rename_table('yourapp_foo', 'yourapp_bar') def backwards(self, orm): db.rename_table('yourapp_bar','yourapp_foo') </code></pre> <p>You can accomplish this more simply using the <code>db_table</code> Meta option in your model class. But every time you do that, you increase the legacy weight of your codebase -- having class names differ from table names makes your code harder to understand and maintain. I fully support doing simple refactorings like this for the sake of clarity.</p> <p>(update) I just tried this in production, and got a strange warning when I went to apply the migration. It said:</p> <blockquote> <pre><code>The following content types are stale and need to be deleted: yourapp | foo Any objects related to these content types by a foreign key will also be deleted. Are you sure you want to delete these content types? If you're unsure, answer 'no'. </code></pre> </blockquote> <p>I answered "no" and everything seemed to be fine.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload