Django for ISchoolers: Difference between revisions

imported>Aldeka
imported>Aldeka
Line 715:
$ python manage.py schemamigration qandabear --auto
</code>
 
You should get a warning message that looks like this:
 
<code>
? The field 'Question.pub_date' does not have a default specified, yet is NOT NULL.
? Since you are removing this field, you MUST specify a default
? value to use for existing rows. Would you like to:
? 1. Quit now, and add a default to the field in models.py
? 2. Specify a one-off value to use for existing columns now
? 3. Disable the backwards migration by raising an exception.
</code>
 
South insists on having a default value for this field just in case, even though we're about to remove it. So, let's do that. Enter '2'.
 
<code>
? Please enter Python code for your one-off default value.
? The datetime module is available, so you can do e.g. datetime.date.today()
</code>
 
pub_date is supposed to be a date of some kind. The default may as well be today!
 
<code>
? Please enter Python code for your one-off default value.
? The datetime module is available, so you can do e.g. datetime.date.today()
>>> datetime.date.today()
</code>
 
South will then happily finish creating your migration.
 
* Apply the migration.
Line 720 ⟶ 748:
<code>
$ python manage.py migrate qandabear
Running migrations for qandabear:
- Migrating forwards to 0002_auto__add_field_answer_votes__del_field_question_pub_date.
> qandabear:0002_auto__add_field_answer_votes__del_field_question_pub_date
- Loading initial data for qandabear.
No fixtures found.
</code>
 
Success!
 
===Save and commit===
Anonymous user