django-admin.py sqlflush error during tests
Asked Answered
B

3

8

I have a set of tests in my Django application that used to pass, but at some point of the software evolution I started to get this kind of message when I run the tests:

Error: Database test_totomanager_demo 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.py sqlflush'. That's the SQL this command wasn't able to run.
The full error: (1105, "MyISAM table 'video_videoinstallation' is in use (most likely by a MERGE table). Try FLUSH TABLES.")

The database is MySQL.

The exact test in which this error starts to occur is unpredictable. It's not the first time it happens, but after one or two tries it used to pass, this time I can't make the tests reach the end.

Any hint on how to avoid this?

Bobsleigh answered 22/12, 2010 at 19:20 Comment(4)
What database? Is the database hosted on the same box or somewhere else? Have you checked the database logs? Have you checked the system logs?Lyda
Database is MySQL, that's only in the tags, sorry. I have checked the /var/log/messages and there's nothing different there. Now I'm trying to reproduce again (stopped happening suddenly) while logging all mysql queries.Bobsleigh
I didn't solve this, but I have avoided. I think it had to do with a test that would fork the process and then exit the child. I recently got an upvote on this, I wonder if other people with this problem have done anything to do with forks.Bobsleigh
does something change when you use innoDB instead of MyISAM?Yawata
H
1

It is probably because your table type is MyISAM which locks the whole table, if you don't need "FULL TEXT SEARCH" in this table then you should make it an innodb table.

I don't know how django tests run, but one possible solution is to run one test at a time instead of running them all at once to avoid testing while table is locked.

Hirschfeld answered 25/3, 2012 at 3:11 Comment(0)
F
1

I was just having this problem myself and realized it's because I had not yet created a migration for a model change.

Try:

./manage.py schemamigration <your_app_name> --auto

I have south migrations installed in this virtualenv, so that's probably a requirement if you don't want to write the migration yourself.

Fiance answered 1/5, 2012 at 14:2 Comment(0)
V
0

Use python's TestCase class instead of Django's.

Replace

from django.test import TestCase
class TestChrono(TestCase):

with

import unittest
class TestChrono(unittest.TestCase):

This is workaround solution but definately it will not affect your test case if you are not using fixtures. Django Testcase try to play with transaction management and so you are getting this error.

Vanzandt answered 24/7, 2015 at 6:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.