Migrate a database in Django
Question: I am getting started with Django through
[this](http://www.youtube.com/watch?v=3DccH9AMwFQ) beautiful video tutorial.On
Tutorial 15 of the video series, there is database migration using **south**.
But when I do `python manage.py migrate signups`, I got a whole lot of errors.
The first error was:

    
    
      File "C:\Python34\lib\site-packages\south\migration\migrators.py", line 164, i
    n _run_migration
        for name, db in south.db.dbs.iteritems():
    AttributeError: 'dict' object has no attribute 'iteritems'
    

I changed `iteritems()` to `items()` to fix that but there is a whole lot of
other errors popping up. My guess is that it has to do with the versions in
action- `South==1.0 Django == 1.6.5 and Python 3.4.1`

Here is the content of my _models.py_ and `for_you, timestamp, updated` are
the attributes added after migration. The commented out attributes were there
originally.

    
    
     `from django.db import models
    
    
    class SignUp(models.Model):
      for_you = models.BooleanField(default = True) 
      first_name = models.CharField(max_length = 120, null=True, blank=True)
      last_name = models.CharField(max_length = 120, null=True, blank=True)
      email = models.EmailField()        
      timestamp = models.DateTimeField(auto_now_add = True, auto_now = False)
      updated = models.DateTimeField(auto_now_add = False, auto_now = True, default=True)
      #timestamp = models.DateTimeField(auto_now_add = False, auto_now = True)
      #timestamp = models.DateTimeField(auto_now_add = True, auto_now = False)
    
     def __str__(self):
         return self.email`
    

The autogenerated
**migrations/0002_auto__add_field_signup_for_you__add_field_signup_updated.py**
looks like

    
    
    # -*- coding: utf-8 -*-
    
    from south.utils import datetime_utils as datetime
    from south.db import db
    from south.v2 import SchemaMigration
    from django.db import models
    
    
    class Migration(SchemaMigration):
    
    def forwards(self, orm):
        # Adding field 'SignUp.for_you'
        db.add_column('signups_signup', 'for_you',
                      self.gf('django.db.models.fields.BooleanField')(default=True),
                      keep_default=False)
    
        # Adding field 'SignUp.updated'
        db.add_column('signups_signup', 'updated',
                      self.gf('django.db.models.fields.DateTimeField')(blank=True, default=True, auto_now=True),
                      keep_default=False)
    
    
    def backwards(self, orm):
        # Deleting field 'SignUp.for_you'
        db.delete_column('signups_signup', 'for_you')
    
        # Deleting field 'SignUp.updated'
        db.delete_column('signups_signup', 'updated')
    
    
    models = {
        'signups.signup': {
            'Meta': {'object_name': 'SignUp'},
            'email': ('django.db.models.fields.EmailField', [], {'max_length': '75'}),
            'first_name': ('django.db.models.fields.CharField', [], {'blank': 'True', 'null': 'True', 'max_length': '120'}),
            'for_you': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
            'last_name': ('django.db.models.fields.CharField', [], {'blank': 'True', 'null': 'True', 'max_length': '120'}),
            'timestamp': ('django.db.models.fields.DateTimeField', [], {'blank': 'True', 'auto_now_add': 'True'}),
            'updated': ('django.db.models.fields.DateTimeField', [], {'blank': 'True', 'default': 'True', 'auto_now': 'True'})
        }
    }
    
    complete_apps = ['signups']
    

And here is the complete error log:

    
    
    Running migrations for signups:
     - Migrating forwards to 0002_auto__add_field_signup_for_you__add_field_signup_u
    pdated.
     > signups:0002_auto__add_field_signup_for_you__add_field_signup_updated
    Traceback (most recent call last):
      File "C:\Python34\lib\site-packages\south\migration\migrators.py", line 175, i
    n _run_migration
        migration_function()
      File "C:\Python34\lib\site-packages\south\migration\migrators.py", line 60, in
     <lambda>
        return (lambda: direction(orm))
      File "D:\Projects\skillshare\src\signups\migrations\0002_auto__add_
    field_signup_for_you__add_field_signup_updated.py", line 19, in forwards
        keep_default=False)
      File "C:\Python34\lib\site-packages\south\db\sqlite3.py", line 35, in add_colu
    mn
        field_default = "'%s'" % field.get_db_prep_save(default, connection=self._ge
    t_connection())
      File "C:\Python34\lib\site-packages\django\db\models\fields\__init__.py", line
     350, in get_db_prep_save
        prepared=False)
      File "C:\Python34\lib\site-packages\django\db\models\fields\__init__.py", line
     911, in get_db_prep_value
        value = self.get_prep_value(value)
      File "C:\Python34\lib\site-packages\django\db\models\fields\__init__.py", line
     895, in get_prep_value
        value = self.to_python(value)
      File "C:\Python34\lib\site-packages\django\db\models\fields\__init__.py", line
     854, in to_python
        parsed = parse_datetime(value)
      File "C:\Python34\lib\site-packages\django\utils\dateparse.py", line 67, in pa
    rse_datetime
        match = datetime_re.match(value)
    TypeError: expected string or buffer
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "manage.py", line 10, in <module>
        execute_from_command_line(sys.argv)
      File "C:\Python34\lib\site-packages\django\core\management\__init__.py", line
    399, in execute_from_command_line
        utility.execute()
      File "C:\Python34\lib\site-packages\django\core\management\__init__.py", line
    392, in execute
        self.fetch_command(subcommand).run_from_argv(self.argv)
      File "C:\Python34\lib\site-packages\django\core\management\base.py", line 242,
     in run_from_argv
        self.execute(*args, **options.__dict__)
      File "C:\Python34\lib\site-packages\django\core\management\base.py", line 285,
     in execute
        output = self.handle(*args, **options)
      File "C:\Python34\lib\site-packages\south\management\commands\migrate.py", lin
    e 111, in handle
        ignore_ghosts = ignore_ghosts,
      File "C:\Python34\lib\site-packages\south\migration\__init__.py", line 220, in
     migrate_app
        success = migrator.migrate_many(target, workplan, database)
      File "C:\Python34\lib\site-packages\south\migration\migrators.py", line 256, i
    n migrate_many
        result = migrator.__class__.migrate_many(migrator, target, migrations, datab
    ase)
      File "C:\Python34\lib\site-packages\south\migration\migrators.py", line 331, i
    n migrate_many
        result = self.migrate(migration, database)
      File "C:\Python34\lib\site-packages\south\migration\migrators.py", line 133, i
    n migrate
        result = self.run(migration, database)
      File "C:\Python34\lib\site-packages\south\migration\migrators.py", line 113, i
    n run
        dry_run.run_migration(migration, database)
      File "C:\Python34\lib\site-packages\south\migration\migrators.py", line 192, i
    n run_migration
        self._run_migration(migration)
      File "C:\Python34\lib\site-packages\south\migration\migrators.py", line 178, i
    n _run_migration
        raise exceptions.FailedDryRun(migration, sys.exc_info())
    south.exceptions.FailedDryRun:  ! Error found during dry run of '0002_auto__add_
    field_signup_for_you__add_field_signup_updated'! Aborting.
    Traceback (most recent call last):
      File "C:\Python34\lib\site-packages\south\migration\migrators.py", line 175, i
    n _run_migration
        migration_function()
      File "C:\Python34\lib\site-packages\south\migration\migrators.py", line 60, in
     <lambda>
        return (lambda: direction(orm))
      File "D:\Projects\skillshare\src\signups\migrations\0002_auto__add_
    field_signup_for_you__add_field_signup_updated.py", line 19, in forwards
        keep_default=False)
      File "C:\Python34\lib\site-packages\south\db\sqlite3.py", line 35, in add_colu
    mn
        field_default = "'%s'" % field.get_db_prep_save(default, connection=self._ge
    t_connection())
      File "C:\Python34\lib\site-packages\django\db\models\fields\__init__.py", line
     350, in get_db_prep_save
        prepared=False)
      File "C:\Python34\lib\site-packages\django\db\models\fields\__init__.py", line
     911, in get_db_prep_value
        value = self.get_prep_value(value)
      File "C:\Python34\lib\site-packages\django\db\models\fields\__init__.py", line
     895, in get_prep_value
        value = self.to_python(value)
      File "C:\Python34\lib\site-packages\django\db\models\fields\__init__.py", line
     854, in to_python
        parsed = parse_datetime(value)
      File "C:\Python34\lib\site-packages\django\utils\dateparse.py", line 67, in pa
    rse_datetime
        match = datetime_re.match(value)
    TypeError: expected string or buffer
    


Answer: There's that problem, you use boolean as a default value (see `default=True`
on line 19 in your migration) for `DateTime` column. That wont work. Just
remove that `default=True` from your model and regenerate your migration.

You would probably need `null=True` in that column or some time-based default
value.

