I'm writing a migration using Django's South, and it can only work on MySQL databases. Is there anyway I can find out what database is being used (i.e. is this running on mysql or is it on postgres, etc.). I want to then raise an exception.
我正在使用Django的South进行迁移,它只能在MySQL数据库上工作。无论如何我都能找到正在使用的数据库(例如,这个数据库是在mysql上运行的还是在postgres上运行的,等等)。然后我想提出一个例外。
I am writing a nontrivial migration (renaming forgein keys), and I think it'll only work on MySQL. In keeping with the south/python ideology of not proceeding if you can't guarantee it'll work, I want to raise an exception if I'm unsure it'll complete successfully.
我正在编写一个重要的迁移(重命名forgein键),我认为它只适用于MySQL。如果你不能保证它能正常运行,那么我就想提出一个例外,如果我不确定它会成功完成的话。
This is for an internal django site that'll almost certainly only run on mysql, however I want to be doubly sure in case.
这是针对一个内部django站点的,该站点几乎肯定只在mysql上运行,但是我要加倍确保以防万一。
1 个解决方案
#1
1
I don't think south says which database the migration was created with, instead of looking at south could you look at the django settings and see what database they have configured.
我不认为南方说的是哪个数据库的迁移是用的,而不是往南看,你可以看看django设置,看看他们已经配置了什么数据库。
Look at the database engines they have set in the settings and if it is something other then "django.db.backends.mysql" throw your exception.
看看他们在设置中设置的数据库引擎,如果它是其他的,那么“django.db.backends”。mysql”抛出异常。
https://docs.djangoproject.com/en/1.3/ref/settings/#engine
https://docs.djangoproject.com/en/1.3/ref/settings/引擎
#1
1
I don't think south says which database the migration was created with, instead of looking at south could you look at the django settings and see what database they have configured.
我不认为南方说的是哪个数据库的迁移是用的,而不是往南看,你可以看看django设置,看看他们已经配置了什么数据库。
Look at the database engines they have set in the settings and if it is something other then "django.db.backends.mysql" throw your exception.
看看他们在设置中设置的数据库引擎,如果它是其他的,那么“django.db.backends”。mysql”抛出异常。
https://docs.djangoproject.com/en/1.3/ref/settings/#engine
https://docs.djangoproject.com/en/1.3/ref/settings/引擎