question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Django "flush" management command fails because of "wagtailsearch_editorspick" table

See original GitHub issue

I’m gearing up to use Wagtail for a new project and ran into a small issue flushing a Postgres database.

With a stock Wagtail installation (no contrib apps), running python manage.py flush fails because of the wagtailsearch_editorspick table:

CommandError: Database sample_project couldn't be flushed. Possible reasons:
  * The database isn't running or isn't configured correctly.
  * At least one of the expected database tables doesn't exist.
  * The SQL was invalid.
Hint: Look at the output of 'django-admin sqlflush'. That's the SQL this command wasn't able to run.
The full error: cannot truncate a table referenced in a foreign key constraint
DETAIL:  Table "wagtailsearch_editorspick" references "wagtailcore_page".
HINT:  Truncate table "wagtailsearch_editorspick" at the same time, or use TRUNCATE ... CASCADE.

After doing some digging, it looks like the key is that this migration leaves the wagtailsearch_editorspick table in the database for the contrib app to pick up:

https://github.com/torchbox/wagtail/blob/master/wagtail/wagtailsearch/migrations/0003_remove_editors_pick.py

Relevant comment:

        # If wagtailsearchpromotions isn't installed, this table will remain
        # in the database unmanaged until it is. This could potentially happen
        # at any point in the future so it's important to keep this behaviour
        # even if we decide to squash these migrations.

I’m new to Wagtail (and really liking it so far!), so I’m not sure what the fix is here. If someone can point me in the right direction, though, I’m happy to put together a PR.

Thanks!

Additional background:

Installed apps:

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',

    # Wagtail
    'wagtail.wagtailcore',
    'wagtail.wagtailadmin',
    'wagtail.wagtaildocs',
    'wagtail.wagtailsnippets',
    'wagtail.wagtailusers',
    'wagtail.wagtailimages',
    'wagtail.wagtailembeds',
    'wagtail.wagtailsearch',
    'wagtail.wagtailsites',
    'wagtail.wagtailredirects',
    'wagtail.wagtailforms',

    'compressor',
    'taggit',
    'modelcluster',

    # Other
    'rest_framework',
)

Requirements:

# Django (1.8 is a long-term support release)
Django==1.8.5

# Third-party libraries
djangorestframework==3.2.4
Pygments==2.0.2
psycopg2==2.6.1
pysaml2==3.0.0
requests==2.7.0
wagtail==1.1

# Testing and debugging
django-debug-toolbar==1.3.2
coverage==4.0
model-mommy==1.2.5

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:19
  • Comments:29 (7 by maintainers)

github_iconTop GitHub Comments

29reactions
thelittlebugcommented, Apr 19, 2020

the simplest solution for me was to add "wagtail.contrib.search_promotions", to my INSTALLED_APPS ->

INSTALLED_APPS = [
    "home",
    "search",
    "wagtail.contrib.search_promotions",
    "wagtail.contrib.forms",
    "wagtail.contrib.redirects",
    "wagtail.contrib.settings",
    # ... more modules

in addition i learned a nifty little trick while reading this issue. you are able to deliver everything before a deadline easily: just move the ticket to the next milestone. works since 1.3 reliably

7reactions
peterlauricommented, Feb 11, 2016

We faced the same problem, but in our case it was just that our test suite started to fail when integrating wagtail into our existing django project. Here is a workaround for someone that want to use wagtail, but not include wagtailsearchpromotions. Please note that this might/will cause problems if you later on want to use wagtailsearchpromotions, as the wagtailsearch_editorspick no longer exists, and the wagtailsearchpromotions initial migration will/might fail. Note that I haven’t tried that path, but I suspect it might fail.

This migration needs to be added to your project. Please note the danger of this migration as well, in case you already have data in wagtailsearch_editorspick as it will remove related rows.

class Migration(migrations.Migration):
    dependencies = [
        ('publicpages', '0001_initial'),  # change this to fit your need
        ('wagtailsearch', '0003_remove_editors_pick'),
    ]

    operations = [
        migrations.RunSQL('DROP TABLE IF EXISTS wagtailsearch_editorspick CASCADE;'),
    ]
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to reset db in Django? I get a command 'reset' not found ...
Merely flushing the tables wasn't fixing a persistent error that occurred when I was deleting objects. Doing a reset_db fixed the problem. Share....
Read more >
#6820 (Error in django/core/management/commands/flush.py ...
The error is caused by the modeltests.fixtures test, and happens because there are non-core-django tables that are related to django-core tables that are ......
Read more >
django_manage – Manages a Django application
The name of the Django management command to run. Built in commands are cleanup, collectstatic, flush, loaddata, migrate, runfcgi, syncdb, ...
Read more >
Clearing the database with Django commands
First, some general design notes on Django management commands. ... Note there's a lot of tables here, because the project also installed ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found