Note that there are some explanatory texts on larger screens.

plurals
  1. POAltering database tables in Django
    primarykey
    data
    text
    <p>I'm considering using Django for a project I'm starting (fyi, a browser-based game) and one of the features I'm liking the most is using <code>syncdb</code> to automatically create the database tables based on the Django models I define (a feature that I can't seem to find in any other framework). I was already thinking this was too good to be true when I saw this in the <a href="https://docs.djangoproject.com/en/dev/ref/django-admin/" rel="noreferrer">documentation</a>:</p> <blockquote> <p>Syncdb will not alter existing tables</p> <p>syncdb will only create tables for models which have not yet been installed. It will never issue ALTER TABLE statements to match changes made to a model class after installation. Changes to model classes and database schemas often involve some form of ambiguity and, in those cases, Django would have to guess at the correct changes to make. There is a risk that critical data would be lost in the process.</p> <p>If you have made changes to a model and wish to alter the database tables to match, use the sql command to display the new SQL structure and compare that to your existing table schema to work out the changes.</p> </blockquote> <p>It seems that altering existing tables will have to be done "by hand".</p> <p>What I would like to know is the best way to do this. Two solutions come to mind:</p> <ul> <li>As the documentation suggests, make the changes manually in the DB;</li> <li>Do a backup of the database, wipe it, create the tables again (with syncdb, since now it's creating the tables from scratch) and import the backed-up data (this might take too long if the database is big)</li> </ul> <p>Any ideas?</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.
 

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