kbussell / django-jsonfield-compat

Compatibility layer for django-jsonfield and Django's native JSONField
MIT License
9 stars 15 forks source link

Django migration error #3

Closed gogson closed 6 years ago

gogson commented 6 years ago

Installing jsonfield-compat makes my migrations fail with this error: TypeError: 'NoneType' object is not subscriptable

Seems like the error in located here https://github.com/kbussell/django-jsonfield-compat/blob/master/jsonfield_compat/convert.py#L23

Any idea how to fix this ?

Operations to perform:
  Apply all migrations: actstream, admin, agency, auth, contenttypes, core, frontend, oauth2_provider, property, sessions, social_django
Running migrations:
  No migrations to apply.
Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 356, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 283, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 330, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 227, in handle
    self.verbosity, self.interactive, connection.alias, apps=post_migrate_apps, plan=plan,
  File "/usr/local/lib/python3.6/site-packages/django/core/management/sql.py", line 53, in emit_post_migrate_signal
    **kwargs
  File "/usr/local/lib/python3.6/site-packages/django/dispatch/dispatcher.py", line 193, in send
    for receiver in self._live_receivers(sender)
  File "/usr/local/lib/python3.6/site-packages/django/dispatch/dispatcher.py", line 193, in <listcomp>
    for receiver in self._live_receivers(sender)
  File "/usr/local/lib/python3.6/site-packages/jsonfield_compat/convert.py", line 48, in handler_convert_json_fields
    convert_model_json_fields(model)
  File "/usr/local/lib/python3.6/site-packages/jsonfield_compat/convert.py", line 43, in convert_model_json_fields
    convert_column_to_json(model, column_name)
  File "/usr/local/lib/python3.6/site-packages/jsonfield_compat/convert.py", line 23, in convert_column_to_json
    current_type = cursor.fetchone()[0].upper()
TypeError: 'NoneType' object is not subscriptable
johnyoonh commented 6 years ago

It seems like this is due to django-activity-stream not creating a field called data. You have to set the USE_JSONFIELD before installing the actstream and then doing the migration: https://github.com/justquick/django-activity-stream/blob/1522fb3a12d16c56a7da3506b370956422cd44cc/actstream/migrations/0002_remove_action_data.py

So comment USE_JSONFIELD

run python manage.py migrate actstream 0001

then set USE_JSONFIELD

python manage.py migrate

The other option you can do is create the field manually with an sql command. data is just a text field

('data', DataField(blank=True, null=True, help_text='')),

gogson commented 6 years ago

I moved away from django-activity-stream, but thanks for the answer it may be useful for other people.