encode / django-rest-framework

Web APIs for Django. 🎸
https://www.django-rest-framework.org
Other
28.21k stars 6.81k forks source link

a question about BooleanField #9407

Closed fanmaoyu0871 closed 4 months ago

fanmaoyu0871 commented 4 months ago

mysql table struct,the column is bit type: 微信图片_20240517102212

mysql data: image

django model : image

drf serializer: image

http response: image

my database value is 0,but it always return ”true“,i don't know why.

angusholder commented 4 months ago

MySQL doesn't have a dedicated bool type, so Django has to store bools as an integer. But models.BooleanField automatically converts the integer back to a bool after loading from the database; this is expected behaviour

fanmaoyu0871 commented 4 months ago

MySQL doesn't have a dedicated bool type, so Django has to store bools as an integer. But models.BooleanField automatically converts the integer back to a bool after loading from the database; this is expected behaviour

you see my value is 0, it's alway return true

auvipy commented 4 months ago

Any questions should be ask here instead https://github.com/encode/django-rest-framework/discussions