# Dynamically populate constraints in Field.contribute\_to\_class

**URL:** <https://forum.djangoproject.com/t/dynamically-populate-constraints-in-field-contribute-to-class/22934>\
**Category:** ORM\
**Created:** [August 9, 2023, 10:28pm UTC](https://forum.djangoproject.com/t/dynamically-populate-constraints-in-field-contribute-to-class/22934 "2023-08-09T22:28:52Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![carltongibson](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/carltongibson/32/267_2.png) [@carltongibson](https://forum.djangoproject.com/u/carltongibson)\
**Post date:** [August 10, 2023, 5:37pm UTC](https://forum.djangoproject.com/t/dynamically-populate-constraints-in-field-contribute-to-class/22934/5 "2023-08-10T17:37:01Z")

</div>

I’d quite like this to work. To generate check constraints from choices would be great.

> [@olivierdalang](#):
>
> It works exactly as I’d like when I specify an empty constraints list in my model’s Meta (meaning makemigrations will create the constraints).
> 
> But for some reason, if I don’t specify an empty list, or if my model has no Meta at all, the constraints aren’t picked up (makemigrations doesn’t create the constraints).

I’d be inclined to reduce that to a test case. Much easier to get people to comment against running code.

Q: does it work generating migrations when you **change** the choices? (Showing that in a test too would be handy.)

---

_[View the full topic](https://forum.djangoproject.com/t/dynamically-populate-constraints-in-field-contribute-to-class/22934)._
