I'm running ubuntu 9.04 32b and got django from Synaptics.
My settings.py is configured for a sqlite3 database.
I've been through this tutorial and got the following error when trying to run the command python manage.py syncdb :
Traceback (most recent call last):
File "manage.py", line 11, in
execute_manager(settings)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/__init__.py", line 340, in execute_manager
utility.execute()
File "/usr/local/lib/python2.6/dist-packages/django/core/management/__init__.py", line 295, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py", line 192, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py", line 219, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py", line 348, in handle
return self.handle_noargs(**options)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/commands/syncdb.py", line 51, in handle_noargs
cursor = connection.cursor()
File "/usr/local/lib/python2.6/dist-packages/django/db/backends/__init__.py", line 56, in cursor
cursor = self._cursor(settings)
File "/usr/local/lib/python2.6/dist-packages/django/db/backends/sqlite3/base.py", line 145, in _cursor
self.connection = Database.connect(**kwargs)
sqlite3.OperationalError: unable to open database file
Do anyone have a clue on my problem ?
In settings.py are you using a relative path to the sqlite file?
If you are, try changing that to an absolute path.
i.e. instead of:
~/project/mydata.db
use
/home/user/project/mydata.db
This can also happen if your database name is the same as your project name. To fix it just change the name of your db e.g. by adding a .db to the NAME. So if your DATABASE NAME in settings.py was 'epic_project' change it to 'epic_project.db'
Long and boring explanation:
If you start your project by running:
django startproject epic_project
your folder structure will be like this:
/path/to/epic_project/
manage.py
epic_project/
settings.py
if then in your settings.py you set your database as:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'epic_project',
...
}
}
when
python manage.py syncdb
runs it tries to open or create a sqlite db file at /path/to/epic_project/epic_project, but there is a directory there, so it says "oh ok the path exists already, let's open it as an sqlite db", unfortunately for sqlite it's a directory and not a DB, so it cries and django presents these tears to you as "sqlite3.OperationalError: unable to open database file"
might be a permission problem, does your user have sufficient right to write on the folder? for example if you do
sudo python manage.py syncdb
instead, does it work?
For Google's sake:
The path to the database must be the full path to the file --- not just the directory where the file lives.
I had the same problem on Windows then realized that syncdb would not create the specified folder if it didn't already exist. I had specified c:/mysite/db/sqlite3.db in settings but the /db/ folder didn't exist. Created it in terminal then re-ran syncdb successfully.
I had the same problem two days ago. I solved it by setting the 'NAME' in the DATABASE dictionary (settings.py) to the absolute path.
For example.
settings.py
DATABASES = {
'default' : {
'ENGINE' : 'django.db.backends.sqlite3',
'NAME' : DATABASE_PATH,
}
}
here you can set the DATABASE_PATH at the top of the settings.py as such
(Not sure if this will work for windows)
SETTINGS_DIR = os.path.dirname(__file__)
PROJECT_PATH = os.path.abspath(os.path.join(SETTINGS_DIR, os.pardir))
DATABASE_PATH = os.path.abspath(os.path.join(PROJECT_PATH, 'your-database-name'))
For Windows you might have to use the replace method. (Not sure .. But you can try it out as follows)
PROJECT_PATH = os.path.abspath(os.path.join(SETTINGS_DIR, os.pardir).replace('\\', '/'))
Same goes for the DATABASE_PATH.
PS. Correct me if I am wrong.
Similar to answer from user104264 - different perspective...
Currently following the YouTube tutorial I had the same error. Seems to me while running the manage.py in a virtualenv django project directory ...path to virtual env.../django_project/, the database name inside /myapp/settings.py was simply 'storage.db' so
(django-v)...path to virtual env project.../django_project/>python manage.py syncdb
created ...path to virtual env project.../django_project/storage.db
-Bill
If you are specifying a full path to db file and are still having issues, try putting an r before the string.
ie.
r'C:\home\usr\mysite\sqlite3.db'
The problem I was running into was a bootstrapping issue where some model lookups were being done at import (outside of any class or function). Per the docs, this is a bad idea.
Related
I'm working with Django version 2.2 . When I run the command
python manage.py collectstatic
I get the following log on bash terminal.
You have requested to collect static files at the destination
location as specified in your settings:
/home/djapp/poorface/staticfiles
This will overwrite existing files!
Are you sure you want to do this?
Type 'yes' to continue, or 'no' to cancel: yes
Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "/home/amit/.virtualenvs/hola/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/home/amit/.virtualenvs/hola/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/amit/.virtualenvs/hola/local/lib/python3.6/site-packages/django/core/management/base.py", line 316, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/amit/.virtualenvs/hola/local/lib/python3.6/site-packages/django/core/management/base.py", line 353, in execute
output = self.handle(*args, **options)
File "/home/amit/.virtualenvs/hola/local/lib/python3.6/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 188, in handle
collected = self.collect()
File "/home/amit/.virtualenvs/hola/local/lib/python3.6/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 114, in collect
handler(path, prefixed_path, storage)
File "/home/amit/.virtualenvs/hola/local/lib/python3.6/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 353, in copy_file
self.storage.save(prefixed_path, source_file)
File "/home/amit/.virtualenvs/hola/local/lib/python3.6/site-packages/django/core/files/storage.py", line 49, in save
return self._save(name, content)
File "/home/amit/.virtualenvs/hola/local/lib/python3.6/site-packages/django/core/files/storage.py", line 288, in _save
os.chmod(full_path, self.file_permissions_mode)
TypeError: an integer is required (got type str)
I changed the permissions of the staticfiles to -rwxrwxrwx . Then also there is no change in output.
manage.py looks like
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "Poorface.settings")
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
This is a hack - not a proper fix!
I had this problem on both OSX and Ubuntu. Seems that certain packages end up with file permission as string, whereas most are integer.
I hacked django to fix this and identified the package causing the problem - django-filebrowser - probably best not to hack django but if desperate here is the change in core/files/storage.py line 289::
if self.file_permissions_mode is not None:
if type(self.file_permissions_mode) == type("duck"):
print(full_path, self.file_permissions_mode, type(self.file_permissions_mode))
self.file_permissions_mode = int(self.file_permissions_mode)
os.chmod(full_path, self.file_permissions_mode)
This reported::
/home/django/teamup/shared_static/filebrowser/css/filebrowser.css 0644 <class 'str'>
I tried changing the file permissions for filebrowser in place in the virtualenv and rerunning but this did not fix the problem so I've gone with the hack.
Yes this question is old but I run into this now again and found the error-source and the proper fix after some tufts of grey hair, tampering all sorts of of file-access-rights and one simple debug-run of "manage.py collectstatic":
In the olden days or maybe in some different context (can't remember how this crept in to my project-dev-settings - in my production setting it was correct) it is/was fine to set the "FILE_UPLOAD_PERMISSIONS" in the settings.py like this:
FILE_UPLOAD_PERMISSIONS = "0644"
According to the docs at least since Django 1.8 the correct setting is:
FILE_UPLOAD_PERMISSIONS = 0o644
after I knew the reason an the solution I also found a few hints that's "now with python 3 … octals … etc. etc." but no connection to this enervating vague error message:
… os.chmod(full_path, self.file_permissions_mode)
TypeError: an integer is required (got type str)
after I used a command python manage.py collectstatic which "allways™" (I know) worked.
So I hope you don't get this much grey hair over some slightly stale projects like me!
I'm working with Django 1.11.5 and using PyCharm as my IDE. I've been trying to refactor my app name from "clinicaltrials" to "cancer_trials". PyCharm updated all of my project files accordingly. I then followed the steps in this SO answer to update the appropriate database tables. However, I'm getting the following error when I try run makemigration. I can't seem to figure out what this means and/or what part I'm missing here.
> python manage.py makemigrations
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "C:\Python_3.6.1\lib\site-packages\django\core\management\__init__.py", line 364, in execute_from_command_line
utility.execute()
File "C:\Python_3.6.1\lib\site-packages\django\core\management\__init__.py", line 356, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python_3.6.1\lib\site-packages\django\core\management\base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Python_3.6.1\lib\site-packages\django\core\management\base.py", line 330, in execute
output = self.handle(*args, **options)
File "C:\Python_3.6.1\lib\site-packages\django\core\management\commands\makemigrations.py", line 150, in handle
loader.project_state(),
File "C:\Python_3.6.1\lib\site-packages\django\db\migrations\loader.py", line 323, in project_state
return self.graph.make_state(nodes=nodes, at_end=at_end, real_apps=list(self.unmigrated_apps))
File "C:\Python_3.6.1\lib\site-packages\django\db\migrations\graph.py", line 409, in make_state
project_state = self.nodes[node].mutate_state(project_state, preserve=False)
File "C:\Python_3.6.1\lib\site-packages\django\db\migrations\migration.py", line 92, in mutate_state
operation.state_forwards(self.app_label, new_state)
File "C:\Python_3.6.1\lib\site-packages\django\db\migrations\operations\fields.py", line 142, in state_forwards
for name, instance in state.models[app_label, self.model_name_lower].fields:
KeyError: ('cancer_trials', 'cancer_trials')
Here's the function that's throwing the error
def state_forwards(self, app_label, state):
new_fields = []
old_field = None
for name, instance in state.models[app_label, self.model_name_lower].fields:
if name != self.name:
new_fields.append((name, instance))
else:
old_field = instance
state.models[app_label, self.model_name_lower].fields = new_fields
# Delay rendering of relationships if it's not a relational field
delay = not old_field.is_relation
state.reload_model(app_label, self.model_name_lower, delay=delay)
In my experience the easiest solution is to create new app and copy the code:
Create new app with the desired name and add it to settings
Copy/paste code from old app to new app, change references from old app to new app, run makemigrations and migrate
Open database and copy data from old tables to new tables
Check that everything works in new app
Search stackoverflow.com or google how to remove app from project or just leave in there. Unfortunately, I'm not 100 % positive about these steps, somebody please correct me if I'm wrong, but to my recollection:
run python manage.py migrate old_app zero (this unapplies all migrations for an app)
remove app from settings
delete files
Remove the all migrations files within your project
Go through each of your projects apps migration folder and remove everything inside, except the init.py file.
Drop the current database, or delete the db.sqlite3 if it is your case.
Create the initial migrations and generate the database schema
try run again migrationsa and migrate commans
OK
if you want to keep the existing database maybe this guide may help you:
https://simpleisbetterthancomplex.com/tutorial/2016/07/26/how-to-reset-migrations.html
(scenario 2)
A nice answer on how to properly move data between apps, can be found here.
What worked for me is the following:
Export the data to json
./manage.py dumpdata --exclude auth.permission --exclude contenttypes --exclude admin.LogEntry --exclude sessions --indent 2 > <path_out_of_the_project>/db.json
Open the db.json file using a capable editor and rename all the instances of the old app name to the new app name.
Rename your app and all the necessary references into your code.
Delete the database and recreate a new empty one applying all the migrations.
Load the data from the db.json file which include the new app name.
./manage.py loaddata <path_out_of_the_project>/db.json
simple approach:
Manually delete all migrations in the apps by going into each apps' 'Migrations' named directory.
Note: deleting init.py in 'Migrations' named directory will not cause any harm.
Above 'appname' is apps taken one-by-one and migrated using above steps. For new apps added will only show migrated table for the next two 'migrate' and 'sqlmigrate' command work.
After this:
$: python manage.py makemigrations appname
$: python manage.py migrate appname
$: python manage.py sqlmigrate appname 0001
I had a working project with django 1.7, and now I moved it to django 1.8.
I can do syncdb and run the app with sqlite, but when I switch to postgres, it fails to do syncdb:
Creating tables...
Creating table x
Creating table y
Running deferred SQL...
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "~/venv/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "~/venv/lib/python2.7/site-packages/django/core/management/__init__.py", line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "~/venv/lib/python2.7/site-packages/django/core/management/base.py", line 390, in run_from_argv
self.execute(*args, **cmd_options)
File "~/venv/lib/python2.7/site-packages/django/core/management/base.py", line 441, in execute
output = self.handle(*args, **options)
File "~/venv/lib/python2.7/site-packages/django/core/management/commands/syncdb.py", line 25, in handle
call_command("migrate", **options)
File "~/venv/lib/python2.7/site-packages/django/core/management/__init__.py", line 120, in call_command
return command.execute(*args, **defaults)
File "~/venv/lib/python2.7/site-packages/django/core/management/base.py", line 441, in execute
output = self.handle(*args, **options)
File "~/venv/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 179, in handle
created_models = self.sync_apps(connection, executor.loader.unmigrated_apps)
File "~/venv/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 317, in sync_apps
cursor.execute(statement)
File "~/venv/lib/python2.7/site-packages/django/db/backends/utils.py", line 79, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "~/venv/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "~/venv/lib/python2.7/site-packages/django/db/utils.py", line 97, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "~/venv/lib/python2.7/site-packages/django/db/backends/utils.py", line 62, in execute
return self.cursor.execute(sql)
django.db.utils.ProgrammingError: relation "auth_user" does not exist
I tried deleting the database and recreating it.
Also, I tried:
python manage.py migrate auth
which also fails:
django.db.utils.ProgrammingError: relation "django_site" does not exist
LINE 1: SELECT (1) AS "a" FROM "django_site" LIMIT 1
Please help get this fixed.
I didn't like the idea of commenting/uncommenting code, so I tried a different approach: I migrated "manually" some apps, and then run django-admin.py migrate for the remaining ones. After deleting all the *.pyc files, my sequence of commands was:
$ django-admin.py migrate auth
$ django-admin.py migrate contentypes
$ django-admin.py migrate sites
$ django-admin.py migrate MY_CUSTOM_USER_APP
$ django-admin.py migrate
where MY_CUSTOM_USER_APP is the name of the application containing the model I set AUTH_USER_MODEL to in my settings file.
Hope it can help. Btw, it seems strange that the best way to synchronize your db in Django 1.8 is so complicated. I wonder if I'm missing something (I'm not very familiar with Django 1.8, I used to work with older versions)
Working on Django 1.10 I found out another solution:
My application is named "web", and first I call:
python manage.py makemigrations web
then I call:
python manage.py makemigrations auth
then I call:
python manage.py migrate
Amazed: IT'S WORKING! :)
It seems auth was searching for the AUTH_USER_MODEL "web.UserProfile" and a relation named web_user_profile, and it didn't find it, hence the error.
On the other hand, calling makemigrations web first creates the required relation first, before auth is able to check and alert it's not there.
Always migrate db with python manage.py makemigrations and then python manage.py migrate in newer versions. For the error above if first time your are migrating your database then use python manage.py migrate --fake-initial. See docs https://docs.djangoproject.com/en/1.9/ref/django-admin/#django-admin-migrate
I had the same problem, and I spent hours banging my head trying to find a solution, which was hidden in the comments. My problem was that CircleCI couldn't run tests because of this error. And I thought I would need to start fresh with a new and empty DB. But I got the same errors. Everything was seemingly related to 'auth', 'contenttypes' and 'sites'.
I read this, and this, as well as this and also this. None were solutions for me.
So after having destroyed my DB and created a new one, the only solution I found to entirely avoid these django.db.utils.ProgrammingError was to:
Comment out all code related to the User model.
Delete all .pyc files in my project! find . -name "*.pyc" -exec rm -- {} + Thanks #max!
run ./manage.py migrate (no fake, no fake-initial, no migration of 'auth' or 'contenttypes' before, juste plain migrate.
Uncomment the above code, and run migrate again!
My INSTALLED_APP is the following:
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.contenttypes',
'django.contrib.sites',
'django.contrib.auth',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'mptt',
'djangobower',
'honeypot',
'django_hosts',
'leaflet',
'multiselectfield',
'corsheaders',
'rest_framework_swagger',
'allauth',
'allauth.account',
# 'allauth.socialaccount',
# 'allauth.socialaccount.providers.twitter',
# 'allauth.socialaccount.providers.facebook',
'project.<app_name>',
)
Deleting migration files, associated .pyc files, and just to be safe all .pyc files with the following commands did not solve my issue.
$ find . -path "*/migrations/*.py" -not -name "__init__.py" -delete
$ find . -path "*/migrations/*.pyc" -delete
$ find . -name "*.pyc" -exec rm -- {} +
What ended up solving my issue wasn't clearing caches, it was because I had a function that performed a query as a default function parameter. On init, which is what commands like makemigrations and migrate do before executing it seems like django (perhaps a python attribute?) initializes all default parameters.
As my database was completely empty (I needed to perform migrate --run-syncdb to recreate the tables) when the below default parameter was initialized, it ran a query against the empty database that subsequently failed.
change this:
def generate_new_addresses(number=1, index=None, wallet=get_active_wallet()):
...
...
return
to:
def generate_new_addresses(number=1, index=None, wallet=None):
if not wallet:
wallet = get_active_wallet()
...
...
return
In my case, this error was appearing when the postgresql driver was able to connect to the database, but the provided user does not have access to the schema or the tables, etc. Instead of saying permission denied, the error being shown is saying that the database table being queried is not being found. Typically in such a situation, the migrate command will also fail with a similar error when it tries to create the django_migrations table.
Check for access being granted on the user you're using in database connection in Django.
I had the same issue, but my underlying cause was the __init__.py file in one of the migrations folders had been deleted from source code but not locally (causing 'Not on my machine' errors).
Migrations folders still need __init__.py files, even with Python 3.
I had this issues with a forms.ChoiceForm queryset. I was able to switch to using forms.ModelChoiceForm which are lazily evaluated and this fixed the problem for me.
In My Case
I made migrations using some other similar looking migration file(1).
Then I deleted it, and made 2 new migration files for replacement(2&3).
And then I was getting this error.
In my case the table was renamed using migration file 1
But django was searching for old table name in migration file 3
So I renamed table manually to old name, and applied migration and It was successful
Error is basically because db (postgres or sqlite) have not found the relation, for which you are inserting or else performing CRUD.
The solution is to make migrations
python manage.py makemigrations <app_name>
python manage.py migrate
I'm working on a new django project and following this tutorial. I'm at the step "Using South for Database Migrations", attempting to run python manage.py syncdb, and I'm getting the following error:
(editorial)[hookedonwinter#hookedonwinter editorial (master *)]$ python manage.py syncdb
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Users/hookedonwinter/.virtualenvs/editorial/lib/python2.6/site-packages/django/core/management/__init__.py", line 453, in execute_from_command_line
utility.execute()
File "/Users/hookedonwinter/.virtualenvs/editorial/lib/python2.6/site-packages/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/hookedonwinter/.virtualenvs/editorial/lib/python2.6/site-packages/django/core/management/__init__.py", line 272, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/Users/hookedonwinter/.virtualenvs/editorial/lib/python2.6/site-packages/django/core/management/__init__.py", line 77, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "/Users/hookedonwinter/.virtualenvs/editorial/lib/python2.6/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/Users/hookedonwinter/.virtualenvs/editorial/lib/python2.6/site-packages/south/management/commands/__init__.py", line 13, in <module>
from south.management.commands.syncdb import Command as SyncCommand
File "/Users/hookedonwinter/.virtualenvs/editorial/lib/python2.6/site-packages/south/management/commands/syncdb.py", line 18, in <module>
from south import migration
File "/Users/hookedonwinter/.virtualenvs/editorial/lib/python2.6/site-packages/south/migration/__init__.py", line 11, in <module>
from south.models import MigrationHistory
File "/Users/hookedonwinter/.virtualenvs/editorial/lib/python2.6/site-packages/south/models.py", line 4, in <module>
class MigrationHistory(models.Model):
File "/Users/hookedonwinter/.virtualenvs/editorial/lib/python2.6/site-packages/django/db/models/base.py", line 97, in __new__
new_class.add_to_class('_meta', Options(meta, **kwargs))
TypeError: Error when calling the metaclass bases
__init__() keywords must be strings
Here is my settings.py file: https://gist.github.com/pjhoberman/5273653
There are no apps yet, just an empty project. I'm guessing it's a simple overlook on my part - any thoughts?
Edit
From the comments:
I don't have any models yet. Just following that tutorial, I'm trying to start with South before I do any model work.
Versions:
Django==1.5.1
South==0.7.6
If I comment out south in settings.py, I get this error:
$ python manage.py syncdb
TypeError: Error when calling the metaclass bases __init__() keywords must be strings
Edit2
I started over and used django 1.4, and it works.
Edit3
I updated python to 2.7 and used django 1.5, and it all works as well.
The "TypeError" at the bottom is the solution. You get this error from Django 1.5 if you use a Python version lower than 2.6.5. There is a Django bug report and a SO discussion on the issue. Arguably the error message is less than intuitive.
The OP is right, none of the answers solved this problem. The solutions are: 1) upgrade Python to 2.7, 2) downgrade Django to 1.4.
I think the problem is with that "~" character you have on your database setting. Try putting #coding=utf-8 as the first or second line of your settings and see what happen.
If that doesn't resolve your problem, change the database filename for one on the same directory of manage.py file like this:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'databasename.sql',
}
}
I tried making a new environment following that tutorial you post and i have no problem. But when i tried to use a database name as you were trying (the one with "~" in its name) i get this error:
(env) user#pc:/path >$ python manage.py syncdb --noinput
Syncing...
OperationalError: unable to open database file
I bet that symbol is the root of your problem... Tell us if this solved your problem!
I updated python to 2.7 and used django 1.5, and it all works as well.
None of the answers actually solved the problem, so I'm answering it myself since I can't delete the question now that there's bounty.
South is very well documented and i'm sure you'll be clear after going through it.
This is the tutorial.
http://south.readthedocs.org/en/0.7.6/tutorial/part1.html
Still to make life simpler..
1) Download south and add it to your apps directory.
2) Add 'south' to INSTALLED APPS in settings.py
3) Run syncdb
4) $ ./manage.py schemamigration appname --initial
5) $ ./manage.py migrate appname
This is all you need for a very basic start.
It seems a DB config problem, try this. 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. Also you can try "python manage.py reset south" to fix possible problems in the APP. If this doesn't work i suggest you start a new problem to discard other errors.
Original post: Django setup with sqlite3?
You need Python 2.6.5+ to run Django 1.5. That's why downgrading to Django 1.4 or upgrading to Python 2.7 was what solved your problem.
https://docs.djangoproject.com/en/dev/releases/1.5/#python-compatibility
Working on the Django tutorial at the moment and got this error when I tried:
python manage.py syncdb
Using sqlite3
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Library/Python/2.6/site-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
utility.execute()
File "/Library/Python/2.6/site-packages/django/core/management/__init__.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Python/2.6/site-packages/django/core/management/base.py", line 196, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Library/Python/2.6/site-packages/django/core/management/base.py", line 232, in execute
output = self.handle(*args, **options)
File "/Library/Python/2.6/site-packages/django/core/management/base.py", line 371, in handle
return self.handle_noargs(**options)
File "/Library/Python/2.6/site-packages/django/core/management/commands/syncdb.py", line 57, in handle_noargs
cursor = connection.cursor()
File "/Library/Python/2.6/site-packages/django/db/backends/__init__.py", line 306, in cursor
cursor = self.make_debug_cursor(self._cursor())
File "/Library/Python/2.6/site-packages/django/db/backends/sqlite3/base.py", line 281, in _cursor
self._sqlite_create_connection()
File "/Library/Python/2.6/site-packages/django/db/backends/sqlite3/base.py", line 271, in _sqlite_create_connection
self.connection = Database.connect(**kwargs)
sqlite3.OperationalError: unable to open database file
My settings.py file reads:
'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': '/Users/username/django_tutorial/mysite',
Anyone know the problem here? it seems like I am putting in the complete file directory, but the databases still couldn't be created? ):
You should use the path to the file, including the file name:
'NAME': '/Users/username/django_tutorial/mysite/data.sqlite',
You can also just give it the file name:
'NAME': 'data.sqlite',
In that case it will be created in the same directory than the one from which you run manage.py.
The best practice is to pass an absolute path, but to ensure this absolute path is created relatively to the settings file. E.G:
import os
SETTINGS_DIR = os.path.dirname(os.path.abspath(__file__))
Then latter:
'NAME': os.path.join(SETTINGS_DIR, 'data.sqlite'),
Remember that the settings file is a Python file, and that you can use Python code in it.
There is a list of Django newbie mistakes on project's wiki. See this entry: https://code.djangoproject.com/wiki/NewbieMistakes#DjangosaysUnabletoOpenDatabaseFilewhenusingSQLite3
This specific error is common mistake among Django's newbies. See detailed description below.
PROBLEM
You're using SQLite3, your DATABASE_NAME is set to the
database file's full path, the database file is writeable by Apache,
but you still get the above error.
SOLUTION
Make sure Apache can also write to the parent directory of
the database. SQLite needs to be able to write to this directory.
Make sure each folder of your database file's full path does not start
with number, eg. /www/4myweb/db (observed on Windows 2000).
If DATABASE_NAME is set to something like
'/Users/yourname/Sites/mydjangoproject/db/db', make sure you've
created the 'db' directory first.
Make sure your /tmp directory is world-writable (an unlikely cause as
other thing on your system will also not work). ls /tmp -ald should
produce drwxrwxrwt ....
Make sure the path to the database specified in settings.py is a full
path.
If you working on windows make also sure that you have the path to the
db directory written with double backlashes
'C:\\django\\sqlite\\django.db'
i dont think you need the full path for the name, just put the file name ie "my_db.db". that is assuming you have sqlite3 installed.