4

I started learning how to write unit tests in Django. To run a couple of example tests for an app named, organizations, I typed this in commandline:

> python manage.py test organizations.tests

which returns migration error like this:

Creating test database for alias 'default'...
FATAL ERROR - The following SQL query failed: ALTER TABLE `smsmessages_message` MODIFY `content` longtext NOT NULL;;
The error was: (1170, "BLOB/TEXT column 'content' used in key specification without a key length")
 ! Error found during real run of migration! Aborting.

 ! Since you have a database that does not support running
 ! schema-altering statements in transactions, we have had
 ! to leave it in an interim state between migrations.

! You *might* be able to recover with:   - no dry run output for alter_column() due to dynamic DDL, sorry

 ! The South developers regret this has happened, and would
 ! like to gently persuade you to consider a slightly
 ! easier-to-deal-with DBMS (one that supports DDL transactions)
 ! NOTE: The error which caused the migration to fail is further up.
Error in migration: smsmessages:0013_auto__chg_field_message_content
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 399, in execute_from_command_line

From Google-ing around for the answer, I found that one way to solve this is to set:

SOUTH_TESTS_MIGRATE = False

in my settings. But that seems like avoiding to solve the root of the problem, which is the migration error. When I was writing my app, I remember using --fake option to skip over some of these hiccups in migration like below:

> python manage.py migrate organizations 0003 --fake

But that command is for real (non-test) database. I would like to know if there's an equivalent command for test database. I checked the tables in my DB and saw that South has created a test database named, test_myapp with its last row in the table south_migrationhistory being 0012_auto__chg_field_message_content. Please let me know how I can step over this 0013 step in the migration for the test_myapp database. If I'm on the wrong track (i.e. if you think I should not fake this migration step 0013 and instead should do something else), please let me know. Thank you very much!

user1330974
  • 2,500
  • 5
  • 32
  • 60
  • Are you getting the migration error for production as well (typically I see that when running stuff on sqlite, which is usually a sign that it's time to switch over to mysql/postgres). Also note that South is effectively deprecated in Django 1.8 – Foon Oct 27 '15 at 02:57
  • @Foon, thanks for the answer. I do not see the error on production. But I have run into migration errors like that a couple of times in production, and used "--fake" to skip over them. Unfortunately, I'm stuck with Django 1.6 with my app at the moment although I do plan to upgrade it soon. What I'd like to know now is if there's a way to use "--fake" with specific database (say, "test_database") in South. Thank you. – user1330974 Oct 27 '15 at 11:35

0 Answers0