Splunk Dev

Using Django to read SQLite DB

AndreasBalster
Explorer

I'm trying to use Django to load some data from a small SQLite database (for testing purposes..).

My Django table model is as follows:

class Coworker(models.Model):
    id = models.IntegerField(primary_key=True)
    firstname = models.CharField(max_length=50)
    lastname = models.CharField(max_length=50)

    def __unicode__(self):
        return self.firstname + " " + self.lastname

In the Django view, I try getting all objects from DB with the following:

items = Coworker.objects.all()

My database config (in __init__.py) looks as follows:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': '/home/j299110/testdb'
    }
}

This gives me the following error message:

Error: ImproperlyConfigured at /de-de/myfirstdjangoapp/coworkers/

settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details.

I then tried moving the DB settings stuff to other files:

  • urls.py
  • views.py
  • /opt/splunk/lib/python2.7/site-packages/django/conf/global_settings.py

But nothing helped, always the same error.

Then I added another, named, data source:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': '/home/j299110/testdb'
    },
    'testdb': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': '/home/j299110/testdb'
    }
}

And tested with

items = Coworker.objects.using("testdb").all()

Now, I got a new error message:

Error: ConnectionDoesNotExist at /de-de/myfirstdjangoapp/coworkers

The connection testdb doesn't exist

Which I find odd since I just added it.

What do I have to do to get a connection to said database?

Tags (3)
0 Karma
1 Solution

LukeMurphey
Champion

This isn't supported because Splunk doesn't include the SQLite C libraries necessary to make the connection. Some people have done it successfully but better methods likely exist. If you want to get data from a SQLite database, try using DB Connect which includes the SQLite driver.

View solution in original post

LukeMurphey
Champion

This isn't supported because Splunk doesn't include the SQLite C libraries necessary to make the connection. Some people have done it successfully but better methods likely exist. If you want to get data from a SQLite database, try using DB Connect which includes the SQLite driver.

Get Updates on the Splunk Community!

Welcome to the Splunk Community!

(view in My Videos) We're so glad you're here! The Splunk Community is place to connect, learn, give back, and ...

Tech Talk | Elevating Digital Service Excellence: The Synergy of Splunk RUM & APM

Elevating Digital Service Excellence: The Synergy of Real User Monitoring and Application Performance ...

Adoption of RUM and APM at Splunk

    Unleash the power of Splunk Observability   Watch Now In this can't miss Tech Talk! The Splunk Growth ...