Django无法正确销毁并创建测试数据库 [英] Django can't destroy and create test databases properly

查看:147
本文介绍了Django无法正确销毁并创建测试数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试运行单元测试时,这就是我得到的:

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

知道为什么会出错吗?

运行最新的自制软件+ 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来缓解这种情况.

When I realised this, I tried to mitigate by reinstalling MySQL via brew.

brew uninstall mysql
brew install mysql

这可以正常工作,当我运行show databases;时,再次出现了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.

似乎事情比brew更复杂. 这就是我再次使其工作的方式:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆