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!

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...