Django OperationalError: unable to open database file


tuna@tuna-VirtualBox:~/Desktop/djangoprojects/mysite$ python manage.py syncdb
OperationalError: unable to open database file

if you get this error most probably you have typo inside settings.py file (NAME field), also arrange chmod 777 for sqllite.db file

DATABASES = {

‘default’: {
‘ENGINE’: ‘django.db.backends.sqlite3‘, # Add ‘postgresql_psycopg2’, ‘mysql’, ‘sqlite3’ or ‘oracle’.
‘NAME’: ‘/home/tuna/Desktop/djangodb/sqllite.db’, # Or path to database file if using sqlite3.
# The following settings are not used with sqlite3:
‘USER’: ”,
‘PASSWORD’: ”,
‘HOST’: ”, # Empty for localhost through domain sockets or ‘127.0.0.1’ for localhost through TCP.
‘PORT’: ”, # Set to empty string for default.
}
}

after that you will see that the tables are created automatically;

tuna@tuna-VirtualBox:~/Desktop/djangoprojects/mysite$ python manage.py syncdb
Creating tables …
Creating table auth_permission
Creating table auth_group_permissions
Creating table auth_group
Creating table auth_user_groups
Creating table auth_user_user_permissions
Creating table auth_user
Creating table django_content_type
Creating table django_session
Creating table django_site

You just installed Django’s auth system, which means you don’t have any superusers defined.
Would you like to create one now? (yes/no): yes
Username (leave blank to use ‘tuna’): tuna

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s