开发者

Django book question: Database config problem. Getting Operational Error

开发者 https://www.devze.com 2023-02-01 20:44 出处:网络
I am on chapter 5 of the django book and trying to proceed, but I\'m stuck on one part: Link to exact chapter: http://www.djangobook.com/en/2.0/chapter05/

I am on chapter 5 of the django book and trying to proceed, but I'm stuck on one part:

Link to exact chapter: http://www.djangobook.com/en/2.0/chapter05/

P开发者_运维技巧roblem: testing database configurations

When I:

  1. Run python manage.py shell form within the mysite project directory
  2. Then in the shell type these commands to test database configuration
from django.db import connection  
cursor = connection.cursor()

I get the following error when i do all of the above:

"OperationalError: unable to open database file"

Was I supposed to create some sort of file within the new directory or folder i created called "MyDB". If so, how do I do this?

Below is how my DB configurations are set:

Configurations:

DATABASES = {

    'default': {
        'ENGINE': 'sqlite3',             
        'NAME':   'C:/Python27/MyDB',      
        'USER': '',                      
        'PASSWORD': '',                 
        'HOST': '',                      
        'PORT': '',                     
    }


My first guess is permissions error. What are the permissions on the Python27 directory, and do they correspond to the permissions from which you are running the python manage command.

I typically put the database in the project directory, not the python directory.


You're using sqlite, which creates a database as a file. From what you've said in the question, the value of NAME in your database setting is 'C:/Python27/MyDB', which points to a directory. Set that value to 'C:/Python27/MyDB/mydb.db' or something similar. You don't need to actually create the file, Django will do that for you when you run manage.py syncdb.

0

精彩评论

暂无评论...
验证码 换一张
取 消