9

I am trying to follow the walkthrough on the django website and I downloaded sqlite and saved it in C:\Windows\System32 folder. When I edit the settings.py file what do I put for the Name field? Do I have to set up a database? The django literature say's that the API should take care of that for sqlite. When I run python manage.py syncdb I just get a bunch of errors. What am I doing wrong?

    Jason & Casey@SUPERBEAST ~/Desktop/mysite
$ python manage.py syncdb
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "c:\Python27\lib\site-packages\django\core\management\__init__.py", line
443, in execute_from_command_line
    utility.execute()
  File "c:\Python27\lib\site-packages\django\core\management\__init__.py", line
382, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "c:\Python27\lib\site-packages\django\core\management\__init__.py", line
252, in fetch_command
    app_name = get_commands()[subcommand]
  File "c:\Python27\lib\site-packages\django\core\management\__init__.py", line
101, in get_commands
    apps = settings.INSTALLED_APPS
  File "c:\Python27\lib\site-packages\django\utils\functional.py", line 184, in
inner
    self._setup()
  File "c:\Python27\lib\site-packages\django\conf\__init__.py", line 42, in _set
up
    self._wrapped = Settings(settings_module)
  File "c:\Python27\lib\site-packages\django\conf\__init__.py", line 93, in __in
it__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "c:\Python27\lib\site-packages\django\utils\importlib.py", line 35, in im
port_module
    __import__(name)
  File "c:\Users\Jason & Casey\Desktop\mysite\mysite\settings.py", line 21
    }
    ^
SyntaxError: invalid syntax

3 Answers 3

18

I haven't tried django under windows but python 2.7 surely comes with sqlite out of the box.

How to setup the database?

on the top of the file:

import os

then:

PROJECT_DIR = os.path.abspath(os.path.dirname(__file__))
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(PROJECT_DIR, 'yourdatabasename.db'),
    }
}

and finally a syncdb should do the trick.

If it doesn't work, mind to paste the traceback?

Sign up to request clarification or add additional context in comments.

6 Comments

how do i paste the traceback? Take a pic and post it?
Windows cmd right?: Right click the title bar, edit > mark. Select the text and press enter. Then paste here.
Edit your question and add it there :)
Sounds like a stale }. Lemme create a pastebin with a demo settings.py that works and give it a run. pastebin.com/v5fN4ifM Its working on me
that worked; I edited `'NAME': os.path.join(PROJECT_DIR, 'test.db')' now where is the test.db saved? is it in my django project folder that I set up?
|
4

The problem is:

  File "c:\Users\Jason & Casey\Desktop\mysite\mysite\settings.py", line 21
    }
    ^
SyntaxError: invalid syntax

Check the syntax a paren or brace hasn't been closed properly around DATABASES.

Comments

0

In Django 4.0+ and Python 3.10+, you can use this code to set up your sqlite database.

on the top of the file:

import os

then:

DATABASE_DIR = os.path.join(BASE_DIR, 'db.sqlite3')
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': DATABASE_DIR,
    }
}

Obs: You can create sqlite database with a custom name

Example:

sqlite3 customName.db

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.