KonradDos
KonradDos

Reputation: 273

Django SQlite configuration

I just started learning Django. My main source of knowledge about that framework is the book "Python Web Development with Django" by Rudolph Snellius, Jeff Forcier and Wesley Chun.

Can you explain to me how to use SQlite in Django? The book is a few years old, which is why I have some problems with configuring the database.

The first step I have done correctly was to create an app with the command ./manage.py startapp blog, then I added verse mojprojekt to tuple INSTALLED_APPS in setting.py file. Then I have to add verses DATABASE_ENGINE = 'sqlite3' and DATABASE_NAME = 'path to my project' to settings.py.

The last step is to run the command ./manage.py syncdb. After this I get an error:

konrad@konrad-MS-7823:~/Documents/Django/mojprojekt$ ./manage.py syncdb
Traceback (most recent call last):
  File "./manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/lib/python2.7/dist-packages/django/core/management/__init__.py", line 354, in execute_from_command_line
    utility.execute()
  File "/usr/lib/python2.7/dist-packages/django/core/management/__init__.py", line 328, in execute
    django.setup()
  File "/usr/lib/python2.7/dist-packages/django/__init__.py", line 18, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/usr/lib/python2.7/dist-packages/django/apps/registry.py", line 85, in populate
    app_config = AppConfig.create(entry)
  File "/usr/lib/python2.7/dist-packages/django/apps/config.py", line 119, in create
    import_module(entry)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
ImportError: No module named blog
konrad@konrad-MS-7823:~/Documents/Django/mojprojekt$ 

Could you help me if you know where I made a mistake?

Update: Here is my application definition:

    # Application definition

    INSTALLED_APPS = (
        'django.contrib.admin',
        'django.contrib.auth',
        'django.contrib.contenttypes',
        'django.contrib.sessions',
        'django.contrib.messages',
        'django.contrib.staticfiles',
        'mojprojekt.blog',

)

This still gives the same result.

Upvotes: 7

Views: 23581

Answers (1)

George Griffin
George Griffin

Reputation: 744

Based on the stacktrace you are receiving, it looks like blog is not in your settings file. Check settings.py, under INSTALLED_APPS and add a new entry for 'blog'.

As far as setting up the database in the latest version of Django, You should have a look at this page from the django settings documentation. According to it, the current style for the DATABASE setting is as follows.

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': 'mydatabase', # This is where you put the name of the db file. 
                 # If one doesn't exist, it will be created at migration time.
    }
}

Upvotes: 16

Related Questions