我开始学习如何在Django中编写单元测试。要为名为organizations
的应用程序运行几个示例测试,我在命令行中键入了这个:
> python manage.py test organizations.tests
返回如下的迁移错误:
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
从谷歌到处寻找答案,我发现解决这个问题的一种方法是设置:
SOUTH_TESTS_MIGRATE = False
在我的设置中。但这似乎避免了解决问题的根源,即迁移错误。当我编写应用程序时,我记得使用--fake
选项跳过迁移中的一些打嗝,如下所示:
> python manage.py migrate organizations 0003 --fake
但该命令适用于真实(非测试)数据库。我想知道是否有与测试数据库相同的命令。我检查了数据库中的表,发现South
创建了一个名为test_myapp
的测试数据库,其表south_migrationhistory
中的最后一行为0012_auto__chg_field_message_content
。请告诉我如何在 test_myapp 数据库的迁移过程中逐步执行此0013
步骤。如果我在错误的轨道上(即如果您认为我不应该伪造此迁移步骤0013
而应该做其他事情),请告诉我。非常感谢你!