Django "flush" management command fails because of "wagtailsearch_editorspick" table
See original GitHub issueI’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:
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:
- Created 8 years ago
- Reactions:19
- Comments:29 (7 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
the simplest solution for me was to add
"wagtail.contrib.search_promotions",
to myINSTALLED_APPS
->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
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.