Search code examples
pythondjangodjango-modelsdjango-migrationsdjango-filter

ImportError: cannot import name 'Random' from 'django.db.models.functions'


Well, I am trying to run my django project in new environment, I installed all of my requirements although every package is installed but it is still giving me below mentioned error. I am not sure but I am guessing it is due to version conflict of some modules. error thrown by compiler

I looked for existing solutions or someone who faced similar situation but no success.


Solution

  • the Random method is located in django/db/models/functions/math.py . change your import statement to this :

    from django.db.models.functions.math import Random