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!

Updated Team Landing Page in Splunk Observability

We’re making some changes to the team landing page in Splunk Observability, based on your feedback. The ...

New! Splunk Observability Search Enhancements for Splunk APM Services/Traces and ...

Regardless of where you are in Splunk Observability, you can search for relevant APM targets including service ...

Webinar Recap | Revolutionizing IT Operations: The Transformative Power of AI and ML ...

The Transformative Power of AI and ML in Enhancing Observability   In the realm of IT operations, the ...