Query SQLite in memory database?

Answered

Hi! I'm testing Django code and my DB (for now) is SQLite. In testing, Django creates a new test DB when you run your tests and the Django docs say that, when using SQLite, that DB is an in-memory DB. So, I'm running my tests in the Pycharm debugger, just to see how things work, and I'd like to set a breakpoint and look at the contents of the testDB as I run a test.

However, I can't find that DB in the Pycharm DB window. I see my normal, development DB but not the temporary, in-memory one. I've refreshed the list of databases but it still doesn't appear.

Any ideas for me? Thanks! 

4
2 comments
Official comment

Hello.

It is not possible to connect to in-memory database created by different process. You may use file-based test database.

See: https://docs.djangoproject.com/en/1.11/ref/settings/#std:setting-DATABASE-TEST

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'USER': 'mydatabaseuser',
        'NAME': 'mydatabase',
        'TEST': {
            'NAME': 'mytestdatabase',
        },
    },
}

 

This config will use "mytestdatabase" which you should see in "Project view". You can then drag-n-drop it to "Database" (see attached image)

 

 

Thank you for the answer, Ilya. I don't think there's any way to override Django's use of the in-memory DB if your back end is SQLite. I'll keep your answer in mind, though, for when I move to a true server DB platform.

0

Please sign in to leave a comment.