1

Here is some code from a Django 3.1 migration:

        migrations.AlterField(
            model_name='foo',
            name='blarg',
            field=models.BigIntegerField(default=theapp.util.make_id, primary_key=True,
                      serialize=False),
        ),

What does the serialize=False mean in this context? I read some code and docs, and it wasn't obvious.

dfrankow
  • 18,326
  • 38
  • 134
  • 193

1 Answers1

1

This means the field will not be part of the serialized object.

for example:

from django.db import models

# You hava a model
class MyModel(models.Model):
    myfield = models.TextField(serialize=False)

# dump data
from django.core import serializers   
data = serializers.serialize("json", MyModel.objects.all())

# myfield will not exist in data
print(data) 

I guess in your context, the field is some automatic generated field.

you can reference this post

Allen Shaw
  • 806
  • 5
  • 17
  • Why does Django decide to specify it, and why isn't it documented at all? Is it ok to remove it? When should and shouldn't I use it or leave it? – odigity May 19 '22 at 23:19