Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Using the <code>choices</code> parameter won't use the ENUM db type; it will just create a VARCHAR or INTEGER, depending on whether you use <code>choices</code> with a CharField or IntegerField. Generally, this is just fine. If it's important to you that the ENUM type is used at the database level, you have three options:</p> <ol> <li>Use "./manage.py sql appname" to see the SQL Django generates, manually modify it to use the ENUM type, and run it yourself. If you create the table manually first, "./manage.py syncdb" won't mess with it.</li> <li>If you don't want to do this manually every time you generate your DB, put some custom SQL in appname/sql/modelname.sql to perform the appropriate ALTER TABLE command.</li> <li>Create a <a href="http://docs.djangoproject.com/en/dev/howto/custom-model-fields/#howto-custom-model-fields" rel="noreferrer">custom field type</a> and define the db_type method appropriately.</li> </ol> <p>With any of these options, it would be your responsibility to deal with the implications for cross-database portability. In option 2, you could use <a href="http://www.djangoproject.com/documentation/model-api/#database-backend-specific-sql-data" rel="noreferrer">database-backend-specific custom SQL</a> to ensure your ALTER TABLE is only run on MySQL. In option 3, your db_type method would need to check the database engine and set the db column type to a type that actually exists in that database.</p> <p><strong>UPDATE</strong>: Since the migrations framework was added in Django 1.7, options 1 and 2 above are entirely obsolete. Option 3 was always the best option anyway. The new version of options 1/2 would involve a complex custom migration using <code>SeparateDatabaseAndState</code> -- but really you want option 3.</p>
 

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