Q:

South syntax error on migrating textfield storing dictionary literal

I am using South 8.4 with Django 1.6.1 with Python 3.3.2 and encountered a bug in South when introducing a textfield to the model:
sources = models.TextField(default="{'users':0}")

South happily migrated when I replaced the string with an empty string.
The traceback:
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "C:\Python33\lib\site-packages\django\core\management\__init__.py", line 399, in execute_from
_command_line
    utility.execute()
  File "C:\Python33\lib\site-packages\django\core\management\__init__.py", line 392, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Python33\lib\site-packages\django\core\management\base.py", line 242, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "C:\Python33\lib\site-packages\django\core\management\base.py", line 285, in execute
    output = self.handle(*args, **options)
  File "C:\Python33\lib\site-packages\south\management\commands\migrate.py", line 111, in handle
    ignore_ghosts = ignore_ghosts,
  File "C:\Python33\lib\site-packages\south\migration\__init__.py", line 220, in migrate_app
    success = migrator.migrate_many(target, workplan, database)
  File "C:\Python33\lib\site-packages\south\migration\migrators.py", line 254, in migrate_many
    result = migrator.__class__.migrate_many(migrator, target, migrations, database)
  File "C:\Python33\lib\site-packages\south\migration\migrators.py", line 329, in migrate_many
    result = self.migrate(migration, database)
  File "C:\Python33\lib\site-packages\south\migration\migrators.py", line 133, in migrate
    result = self.run(migration, database)
  File "C:\Python33\lib\site-packages\south\migration\migrators.py", line 114, in run
    return self.run_migration(migration, database)
  File "C:\Python33\lib\site-packages\south\migration\migrators.py", line 84, in run_migration
    migration_function()
  File "C:\Python33\lib\site-packages\south\migration\migrators.py", line 60, in <lambda>
    return (lambda: direction(orm))
  File "C:\Users\Johnson\Documents\Works\Django\timewatch\times\migrations\0007_auto__add_field_acti
vity_sources.py", line 14, in forwards
    keep_default=False)
  File "C:\Python33\lib\site-packages\south\db\sqlite3.py", line 38, in add_column
    field.column: (self._column_sql_for_create(table_name, name, field, False), field_default)
  File "C:\Python33\lib\site-packages\south\db\generic.py", line 47, in _cache_clear
    return func(self, table, *args, **opts)
  File "C:\Python33\lib\site-packages\south\db\sqlite3.py", line 113, in _remake_table
    self._copy_data(table_name, temp_name, renames, added)
  File "C:\Python33\lib\site-packages\south\db\sqlite3.py", line 149, in _copy_data
    self.quote_name(src),
  File "C:\Python33\lib\site-packages\south\db\generic.py", line 282, in execute
    cursor.execute(sql, params)
  File "C:\Python33\lib\site-packages\django\db\backends\util.py", line 69, in execute
    return super(CursorDebugWrapper, self).execute(sql, params)
  File "C:\Python33\lib\site-packages\django\db\backends\util.py", line 53, in execute
    return self.cursor.execute(sql, params)
  File "C:\Python33\lib\site-packages\django\db\utils.py", line 99, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "C:\Python33\lib\site-packages\django\utils\six.py", line 490, in reraise
    raise value.with_traceback(tb)
  File "C:\Python33\lib\site-packages\django\db\backends\util.py", line 53, in execute
    return self.cursor.execute(sql, params)
  File "C:\Python33\lib\site-packages\django\db\backends\sqlite3\base.py", line 450, in execute
    return Database.Cursor.execute(self, query, params)
django.db.utils.OperationalError: near "':0}'": syntax error

Anyone know what's causing this error?

A:

1) ' must be escaped.
2) I see you wanted store JSON in field? So keys must be quoted with " quotes http://www.w3schools.com/json/json_syntax.asp
So, I think this will solve the problem
sources = models.TextField(default='{"users":0}')

Just replaced quotes

