Django无法正确破坏和创建测试数据库 [英] Django can't destroy and create test databases properly
问题描述
当我尝试运行我的单元测试时,这就是我所得到的:
When I try to run my unittest, this is what I get:
python manage.py test dbank --settings=databank_web.settings.dqs.dev_hooman
Creating test database for alias 'default'...
Creating test database for alias 'global'...
Creating test database for alias 'optin_db'...
Creating test database for alias 'vpd3'...
Creating test database for alias 'user_db'...
Creating test database for alias 'vpd1'...
Creating test database for alias 'vpd2'...
.
----------------------------------------------------------------------
Ran 1 test in 0.327s
OK
Destroying test database for alias 'default'...
Warning: Table 'mysql.proc' doesn't exist
它不能破坏数据库。当我重新运行测试时,它变得更好:
It couldn't destroy the database. It gets better, when I rerun the test:
python manage.py test dbank --settings=databank_web.settings.dqs.dev_hooman
Creating test database for alias 'default'...
Creating test database for alias 'global'...
Got an error creating the test database: (1007, "Can't create database 'test_dqs12_full2'; database exists")
Type 'yes' if you would like to try deleting the test database 'test_dqs12_full2', or 'no' to cancel: yes
Destroying old test database 'global'...
Got an error recreating the test database: Table 'mysql.proc' doesn't exist
任何想法为什么会出错?
Any idea why this is going wrong?
运行最新的homebrew + mysql-5.6.21 + Django 1.5.5
Running latest homebrew + mysql-5.6.21 + Django 1.5.5
推荐答案
我终于找到了理由。
我们的应用程序有大约7个数据库。当我要手动删除它们以获得干净的状态时,我不小心也删除了 mysql
数据库。这个数据库不应该被删除,因为它包含有关root用户的重要信息。
Our application has around 7 databases. When I was about to drop them manually to get a clean state, I accidentally also dropped the mysql
database. This database should not be ever deleted, as it contains vital information about the root user.
当我意识到这一点时,我尝试通过brew重新安装MySQL来缓解。 p>
When I realised this, I tried to mitigate by reinstalling MySQL via brew.
brew uninstall mysql
brew install mysql
当我运行显示数据库时,这个工作和
,但问题仍然存在。这是当我来到这里寻求帮助。 mysql
数据库再次出现;
This worked and mysql
database showed up again when I ran show databases;
, however the problem persisted. Thats when I came here for help.
因为它似乎比酿造有点复杂。
这是我如何让它再次工作:
As it seems things are a bit more complicated than that with brew. This is how I got it working again:
1) brew uninstall mysql
2) sudo rm -r /usr/local/var/mysql/
3) brew install mysql
4) unset TMPDIR
5) mysql_install_db --verbose --user='whoami' --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp
6) mysql.server restart
7) mysql_secure_installation
现在它可以工作。希望这有助于其他mac用户。谢谢。
Now it works. Hope this helps other fellow mac users. Thanks.
这篇关于Django无法正确破坏和创建测试数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!