Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 832
lfagundes Avatar asked Dec 22 '10 19:12

lfagundes


2 Answers

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.

like image 94
Mosab Ibrahim Avatar answered Sep 21 '22 01:09

Mosab Ibrahim


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.

like image 29
jooks Avatar answered Sep 23 '22 01:09

jooks