justquick / django-activity-stream

Generate generic activity streams from the actions on your site. Users can follow any actors' activities for personalized streams.
http://django-activity-stream.rtfd.io/en/latest/
BSD 3-Clause "New" or "Revised" License
2.36k stars 483 forks source link

Missing migration when moving from Django 2.2 to 3.2 #508

Closed wrvdklooster closed 2 years ago

wrvdklooster commented 2 years ago

When running makemigrations in a project using django-activity-stream with USE_JSONFIELD=True a new migration is created.

Caused by this code I assume:

DataField = models.TextField

if USE_JSONFIELD:
    if django.VERSION >= (3, 1):
        from django.db.models import JSONField
        DataField = JSONField

Migration created is actstream/migrations/0004_alter_action_data.py:

# Generated by Django 3.2.13 on 2022-06-03 19:24

import django.core.serializers.json
from django.db import migrations, models

class Migration(migrations.Migration):

    dependencies = [
        ('actstream', '0003_add_follow_flag'),
    ]

    operations = [
        migrations.AlterField(
            model_name='action',
            name='data',
            field=models.JSONField(blank=True, encoder=django.core.serializers.json.DjangoJSONEncoder, null=True),
        ),
    ]

Things still work as expected. The data type in our database for that column is text, but the JSONField from Django handles it correctly.

The migration doesn’t generate any sql statement (checked using sqlmigrate actstream 0004).

We could probably write a migration to store the data as JSON in PostgreSQL but not sure if that is the correct fix.

justquick commented 2 years ago

Since the USE_JSONFIELD setting is optional, i do not include that migration in the package. If you want to add it then you can do that additional migration like you are doing. It's a sore subject having an optional field being added really makes the migrations tricky