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!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...