south: updating boolean field

ApathyBear

Say I have this model:

class Knight(models.Model):
    name = models.CharField(max_length=100)
    of_the_round_table = models.BooleanField()

And Say I want to change it to this:

class Knight(models.Model):
    name = models.CharField(max_length=100)
    round_table = models.BooleanField()

After schemamigration southtut --auto --update , South prompts me with the inevitable upon :

 ? The field 'Knight.of_the_round_table' does not have a default specified, yet is NOT NULL.
 ? Since you are adding 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
 ? Please select a choice: 2
 ? Please enter Python code for your one-off default value.
 ? The datetime module is available, so you can do e.g. datetime.date.today()
 >>> "True"

At the end of it all, when I tried to migrate with ./manage.py migrate someapp I recieved this:

ValueError: invalid literal for int() with base 10: 'True'

Not really sure why the "True" is incorrect. I believe I tried entering it without parenthesis and it gave that as well. What am I doing wrong here? How should I enter a default value?

Edit: Additional Question - why does south ask me to enter a value for each previous migration as well? If I migrated again and it changed the name of 'round_table' to 'table', it would ask me to set defaults for 'of_the_round_table = models.BooleanField()', 'round_table = models.BooleanField()', and 'table = models.BooleanField()'. Why? Shouldn't it only ask for the latest one and is there anyway to make this process faster? I can see it being a pain if you have made many migrations in the past.

cmd
  1. "True" is not a boolean value its a string. Use True.

  2. South can not only migrate forward, but backwards as well. If migrating backwards it needs to know what values to put in the 'new' column of_the_round_table. It may be easier to just specify defaults on your not null fields or better yet define your migration as a rename_column instead of a removing one column and adding another (as auto does for you).

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related