Note that there are some explanatory texts on larger screens.

plurals
  1. POGet DB Type in Django
    primarykey
    data
    text
    <p>I need to be able to determine the DB type used during run time in Django.</p> <pre><code>MYSQL = False if &lt;something goes here&gt;: MYSQL = True </code></pre> <p>I saw a related Django ticket, but didn't quite get me to my solution. (<a href="https://code.djangoproject.com/ticket/18332" rel="nofollow">https://code.djangoproject.com/ticket/18332</a>)</p> <p>It'd be nice to have a solution that I can determine if it's a MySQL, PostgreSQL, SQLite, Oracle...whatever.</p> <p>I've tried digging through <code>django.db</code> but can't see anything that will help.</p> <p>I'll elaborate on what I'm trying to do as it seems misunderstood. This is for a testing utility project that is independent of any Django project. My utility needs to understand which database is being used to prevent illegal activity.</p> <p>For example, my package supports PostgreSQL hstore fields, but no such field exists in, say, SQLite. So, I don't want to allow specific functionality if they are using SQLite.</p> <p>I have access to their Django model used with the utility.</p> <pre><code>from my_app.models import Foo testing_utility(Foo, **kwargs) </code></pre> <p>My <code>testing_utility</code> signature is:</p> <pre><code>def testing_utility(klass, **kwargs): instance = klass(**kwargs) </code></pre> <p>Now, I don't want to preform <code>hstore</code> specific functionality on this class if isn't a PostgreSQL DB. Does this clear it up some more?</p> <p>EDIT 1:</p> <p>Thanks, KevinDTimm, for the link. It looks like Django models do have <code>._state.db</code> upon instantiation. Of course, my instance has a <code>None</code> type. :(</p> <pre><code>&gt;&gt; print(instance._state.db) None </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload