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!

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 ...

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...