Skip to content

id column integer primary key of 0 gets returned as null #1244

Closed
@tonytony99

Description

@tonytony99

If a model has an id column that's an integer primary key

class Person(models.Model):
    id = models.IntegerField(primary_key=True)
    name = models.CharField(max_length=200)

and a fixture is loaded where the id has value 0

[
    {"model": "project.person", "fields": {"id": 0, "name": "Example"}},
    {"model": "project.person","fields": {"id": 1, "name": "Someone"}}
]

then the JSON response returned from the API replaces the id of 0 with null

    "data": [
        {
            "type": "person",
            "id": null,
            "attributes": {
                "name": "Example"
            }
        },
        {
            "type": "person",
            "id": "1",
            "attributes": {
                "name": "Someone"
            }
        }
    ],

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions