lfagundes
lfagundes

Reputation: 3068

django-admin.py sqlflush error during tests

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?

Upvotes: 8

Views: 1389

Answers (3)

jatinkumar patel
jatinkumar patel

Reputation: 2990

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.

Upvotes: 0

jooks
jooks

Reputation: 1287

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.

Upvotes: 1

Mosab Ibrahim
Mosab Ibrahim

Reputation: 133

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.

Upvotes: 1

Related Questions