WagtailWagtail

Fixing the `Query` import error while upgrading Wagtail from 5 to 7

Oct 17, 2025 · by Tim Kamanin

While upgrading an old project from Wagtail 5 to 7, I encountered this error:

ImportError: cannot import name 'Query' from 'wagtail.search.models'

After some searching, I found out what’s wrong. It turns out Wagtail moved the Query model from wagtail.search.models to wagtail.contrib.search_promotions in version 5, but until version 6, you could still use the old import. Therefore, the version 7 upgrade led to the above error.

The fix

Luckily, the solution is simple (as with most things involving Wagtail ❤️). We fix it in three quick steps:

Step 1: Add the new wagtail.contrib.search_promotions app to INSTALLED_APPS

INSTALLED_APPS = [
    # ...
    "wagtail.contrib.search_promotions",
]

Step 2: Update imports

# Old
from wagtail.search.models import Query

# New
from wagtail.contrib.search_promotions.models import Query

Step 3: Run migrations

python manage.py migrate

And that’s it - Query now lives under wagtail.contrib.search_promotions, and your project should load normally again.

Hey, if you've found this useful, please share the post to help other folks find it:

There's even more:

Subscribe for updates