django call_command syncdb failed: unable to open database file - database

I want to add some python codes after syncdb, so I decide to write a build.py which does everything including syncdb.
I write something in build.py as:
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
from django.core.management import call_command
from django.contrib.auth.models import User
call_command('syncdb', interactive=False)
But when I run build.py, it said:
Traceback (most recent call last):
File "/home/csimstu/PycharmProjects/TeenHope/TeenHope/build.py", line 5, in <module>
call_command('syncdb', interactive=False)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 161, in call_command
return klass.execute(*args, **defaults)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 255, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 385, in handle
return self.handle_noargs(**options)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/syncdb.py", line 56, in handle_noargs
cursor = connection.cursor()
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/__init__.py", line 324, in cursor
cursor = self.make_debug_cursor(self._cursor())
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/sqlite3/base.py", line 306, in _cursor
self._sqlite_create_connection()
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/sqlite3/base.py", line 296, in _sqlite_create_connection
self.connection = Database.connect(**kwargs)
sqlite3.OperationalError: unable to open database file
I've tried ./manage.py syncdb and use call_command in interactive shell mode, and both ways worked perfectly okay. How could it be?

If the database file isn't found that's probably because you didn't use a full path in your settings.
import os
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.realpath(os.path.join(os.path.dirname(__file__), "relative_path_here", "database.db")),
Out of topic: I'd recommend to use Fabric for this kind of commands.

Related

I created a virtual environmnt for my new projec, instaled django and started the new project. whnvr I run code with manage.py i get this long error

`when i run line of code: python manage.py startapp blog error below displays
Traceback (most recent call last):
File "C:\Users\lenevo\Desktop\portfolio-project\manage.py", line 22, in <module>
main()
File "C:\Users\lenevo\Desktop\portfolio-project\manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "C:\Users\lenevo\Desktop\reemaenv\Lib\site-packages\django\core\management_init_.py", line 381, in execute_from_command_line
utility.execute()
File "C:\Users\lenevo\Desktop\reemaenv\Lib\site-packages\django\core\management_init_.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\lenevo\Desktop\reemaenv\Lib\site-packages\django\core\management\base.py", line 336, in run_from_argv
connections.close_all()
File "C:\Users\lenevo\Desktop\reemaenv\Lib\site-packages\djayour textngo\db\utils.py", line 224, in close_all
connection.close()
File "C:\Users\lenevo\Desktop\reemaenv\Lib\site-packages\django\db\backends\sqlite3\base.py", line 248, in close
if not self.is_in_memory_db():
^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\lenevo\Desktop\reemaenv\Lib\site-packages\django\db\backends\sqlite3\base.py", line 367, in is_in_memory_db
return self.creation.is_in_memory_db(self.settings_dict['NAME'])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\lenevo\Desktop\reemaenv\Lib\site-packages\django\db\backends\sqlite3\creation.py", line 12, in is_in_memory_db
return database name == ':memory:' or 'mode=memory' in database name
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Type Error: argument of type 'Windows Path' is not Iterable
plz help me solve this problem `

database Django on jython

please i need help connecting database with jython on django and help me with the server when i put jython manage.py runserver the server don´t run
DATABASES = {
'default': {
#'ENGINE': 'doj.backends.zxjdbc.sqlite3',
'ENGINE': 'django.db.backends.mysql',
'NAME': 'tanagraweb',
'USER': 'root',
'PASSWORD': 'root',
'HOST': '127.0.0.1',
'PORT': '3306',
}
}
and django throw this:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\jython2.7b3\Lib\site-packages\django\core\management\__init__.py", line 399, in execute_from_command_line
utility.execute()
File "C:\jython2.7b3\Lib\site-packages\django\core\management\__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\jython2.7b3\Lib\site-packages\django\core\management\base.py", line 242, in run_from_argv
self.execute(*args, **options.__dict__)
File "C:\jython2.7b3\Lib\site-packages\django\core\management\base.py", line 280, in execute
translation.activate('en-us')
File "C:\jython2.7b3\Lib\site-packages\django\utils\translation\__init__.py", line 130, in activate
return _trans.activate(language)
File "C:\jython2.7b3\Lib\site-packages\django\utils\translation\trans_real.py", line 188, in activate
_active.value = translation(language)
File "C:\jython2.7b3\Lib\site-packages\django\utils\translation\trans_real.py", line 177, in translation
default_translation = _fetch(settings.LANGUAGE_CODE)
File "C:\jython2.7b3\Lib\site-packages\django\utils\translation\trans_real.py", line 159, in _fetch
app = import_module(appname)
File "C:\jython2.7b3\Lib\site-packages\django\utils\importlib.py", line 40, in import_module
__import__(name)
File "C:\jython2.7b3\Lib\site-packages\django\contrib\admin\__init__.py", line 6, in <module>
from django.contrib.admin.sites import AdminSite, site
File "C:\jython2.7b3\Lib\site-packages\django\contrib\admin\sites.py", line 4, in <module>
from django.contrib.admin.forms import AdminAuthenticationForm
File "C:\jython2.7b3\Lib\site-packages\django\contrib\admin\forms.py", line 6, in <module>
from django.contrib.auth.forms import AuthenticationForm
File "C:\jython2.7b3\Lib\site-packages\django\contrib\auth\forms.py", line 17, in <module>
from django.contrib.auth.models import User
File "C:\jython2.7b3\Lib\site-packages\django\contrib\auth\models.py", line 47, in <module>
#python_2_unicode_compatible
File "C:\jython2.7b3\Lib\site-packages\django\db\models\base.py", line 96, in __new__
new_class.add_to_class('_meta', Options(meta, **kwargs))
File "C:\jython2.7b3\Lib\site-packages\django\db\models\base.py", line 264, in add_to_class
value.contribute_to_class(cls, name)
File "C:\jython2.7b3\Lib\site-packages\django\db\models\options.py", line 124, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "C:\jython2.7b3\Lib\site-packages\django\db\__init__.py", line 34, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "C:\jython2.7b3\Lib\site-packages\django\db\utils.py", line 198, in __getitem__
backend = load_backend(db['ENGINE'])
File "C:\jython2.7b3\Lib\site-packages\django\db\utils.py", line 113, in load_backend
return import_module('%s.base' % backend_name)
File "C:\jython2.7b3\Lib\site-packages\django\db\utils.py", line 113, in load_backend
return import_module('%s.base' % backend_name)
File "C:\jython2.7b3\Lib\site-packages\django\utils\importlib.py", line 40, in import_module
__import__(name)
File "C:\jython2.7b3\Lib\site-packages\django\db\backends\mysql\base.py", line 17, in <module>
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb
i research and found that is the connector of mysql but i don´t know why this does´t work
if anyone has a project in jython on django i will be so much gratefull this is too hard
Although MySQLdb is the most widely used MySql library among the Python/Django community, you can't use it because Jython does not work with C extensions.
To use Jython with Django, you need to install django-jython and set the db backend to 'ENGINE': 'doj.db.backends.mysql'
This is documented in the official doc Running Django on Jython
Install pymysql with "pip install pymysql"
Add the following to your manage.py file:
import pymysql
pymysql.install_as_MySQLdb()
In your DATABASES setting, use:
ENGINE': 'django.db.backends.mysql',

Why am I getting MultiQuery exception on 1.4 nonrel?

I'm testing an upgrade on NonRel for App Engine to 1.4 from 1.3. It works fine locally, but when I deploy to App Engine, I get a syncdb error in the end of deployment:
Running syncdb.
2013-08-02 09:31:34,600 WARNING simple_search_stub.py:998 Could not read search indexes from /var/folders/fv/cdp4hprx5pbc_3bf5g0wbbkw0000gn/T/dev_appserver.searchindexes
Creating tables ...
The following content types are stale and need to be deleted:
auth | message
Any objects related to these content types by a foreign key will also
be deleted. Are you sure you want to delete these content types?
If you're unsure, answer 'no'.
Type 'yes' to continue, or 'no' to cancel: yes
Traceback (most recent call last):
File "manage.py", line 9, in <module>
execute_from_command_line(sys.argv)
File "/src/django/core/management/__init__.py", line 443, in execute_from_command_line
utility.execute()
File "/src/django/core/management/__init__.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/src/djangoappengine/management/commands/deploy.py", line 72, in run_from_argv
run_appcfg(argv)
File "/src/djangoappengine/management/commands/deploy.py", line 51, in run_appcfg
call_command('syncdb', remote=True, interactive=True)
File "/src/django/core/management/__init__.py", line 150, in call_command
return klass.execute(*args, **defaults)
File "/src/django/core/management/base.py", line 232, in execute
output = self.handle(*args, **options)
File "/src/django/core/management/base.py", line 371, in handle
return self.handle_noargs(**options)
File "/src/django/core/management/commands/syncdb.py", line 110, in handle_noargs
emit_post_sync_signal(created_models, verbosity, interactive, db)
File "/src/django/core/management/sql.py", line 189, in emit_post_sync_signal
interactive=interactive, db=db)
File "/src/django/dispatch/dispatcher.py", line 172, in send
response = receiver(signal=self, sender=sender, **named)
File "/src/django/contrib/contenttypes/management.py", line 67, in update_contenttypes
ct.delete()
File "/src/django/db/models/base.py", line 599, in delete
collector.delete()
File "/src/django/db/models/deletion.py", line 61, in decorated
func(self, *args, **kwargs)
File "/src/django/db/models/deletion.py", line 261, in delete
query.delete_batch([obj.pk for obj in instances], self.using, field)
File "/src/django/db/models/sql/subqueries.py", line 44, in delete_batch
self.do_query(self.model._meta.db_table, where, using=using)
File "/src/django/db/models/sql/subqueries.py", line 29, in do_query
self.get_compiler(using).execute_sql(None)
File "/src/djangotoolbox/db/basecompiler.py", line 593, in execute_sql
self.build_query([self.query.get_meta().pk]).delete()
File "/src/djangoappengine/db/compiler.py", line 69, in _func
return func(*args, **kwargs)
File "/src/djangoappengine/db/compiler.py", line 168, in delete
Delete(keys)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/api/datastore.py", line 695, in Delete
return DeleteAsync(keys, **kwargs).get_result()
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/api/datastore.py", line 674, in DeleteAsync
keys, _ = NormalizeAndTypeCheckKeys(keys)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/api/datastore.py", line 176, in NormalizeAndTypeCheckKeys
keys, multiple = NormalizeAndTypeCheck(keys, (basestring, Entity, Key))
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/api/datastore.py", line 143, in NormalizeAndTypeCheck
arg_list = list(arg)
File "/src/djangoappengine/db/compiler.py", line 105, in fetch
query = self._build_query()
File "/src/djangoappengine/db/compiler.py", line 69, in _func
return func(*args, **kwargs)
File "/src/djangoappengine/db/compiler.py", line 322, in _build_query
return MultiQuery(self.gae_query, self.ordering)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/api/datastore.py", line 1998, in __init__
'MultiQuery does not support keys_only.')
django.db.utils.DatabaseError: MultiQuery does not support keys_only.
I am able to work around it by deleting the content types on my local development server, but I'm wondering why I'm getting this error. I do understand what the exception says, but don't understand why NonRel has not adapted Django to perform this operation properly in App Engine?
This could be a bug in a path of the djangoappengine compiler that isn't utilized much. There was another delete related bug a few months ago:
https://groups.google.com/forum/#!searchin/django-non-relational/delete/django-non-relational/Eb6K7fVYrhM/_QmLPtbIfmMJ
That being said, I'm not even sure why djangoappengine runs syncdb at all when you deploy. It runs syncdb locally, not on the production server. It seems unnecssary, I suspect it's just a byproduct of some existing django codepath.
I encontered a simillar error can you try
./manage.py sqlflush

Using SQL Server backend with Django

I'm trying to connect to an external SQL Server Express database using the django-pyodbc version at: this github link but I keep getting this error when I run manage.py shell to check if I can execute come ORM commands
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.7/site-packages/django/core/management/base.py", line 196, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/local/lib/python2.7/site-packages/django/core/management/base.py",line 232, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python2.7/site-packages/django/core/management/base.py",line 371, in handle
return self.handle_noargs(**options)
File "/usr/local/lib/python2.7/site-packages/django/core/management/commands/shell.py", line 45, in handle_noargs
from django.db.models.loading import get_models
File "/usr/local/lib/python2.7/site-packages/django/db/__init__.py", line 40, in <module>
backend = load_backend(connection.settings_dict['ENGINE'])
File "/usr/local/lib/python2.7/site-packages/django/db/__init__.py", line 34, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/usr/local/lib/python2.7/site-packages/django/db/utils.py", line 93, in __getitem__
conn = backend.DatabaseWrapper(db, alias)
File "/usr/local/lib/python2.7/site-packages/sql_server/pyodbc/base.py", line 133, in __init__
self.ops = DatabaseOperations(self)
File "/usr/local/lib/python2.7/site-packages/sql_server/pyodbc/operations.py", line 10, in __init__
super(DatabaseOperations, self).__init__()
TypeError: __init__() takes exactly 2 arguments (1 given)
My settings.py has this:
DATABASES = {
'default': {
'ENGINE': 'sql_server.pyodbc',
'NAME': 'DBName',
'HOST': '192.168.29.1',
'USER': 'user',
'PASSWORD': 'pswd',
'PORT': 1433,
}
}
DATABASE_OPTIONS = {
'driver': '/usr/local/lib/libtdsodbc.so',
'dsn': 'FreeTDS',
'extra_params': "TDS_VERSION=8.0"
}
I'm completely at a loss as to what I'm supposed to do, so all ideas are welcome. Essentially what I want is to be able to use a small app I've made to interface with the SQL Server database, while being able to use normal DJango ORM commands inplace of pyodbc connection strings (and BTW using pyodbc, I can connect to the SQL Server database without an issue)
it seem to me that you are using the old repo for django-pyodbc at http://code.google.com/p/django-pyodbc/
make sure to cleanly uninstall the old version and then reinstall
pip uninstall sql-server.pyodbc
pip install git+https://github.com/avidal/django-pyodbc.git

South migration schemamigration doesn't work

Just to make sure I have the setup right in my current django project, I did the following:
added south to installed_apps
manage.py syncdb (using windows)
manage.py convert_to_south app
I didn't make changes to my database yet but whether or not I do, I run:
manage.py schemamigration app --auto
and I get the following errors:
Traceback (most recent call last):
File "manage.py", line 17, 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\base.py", line 196, in run_from_ar
gv
self.execute(*args, **options.__dict__)
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 232, in execute
output = self.handle(*args, **options)
File "C:\Python27\lib\site-packages\south\management\commands\schemamigration.py", line 98, i
n handle
old_orm = last_migration.orm(),
File "C:\Python27\lib\site-packages\south\utils.py", line 62, in method
value = function(self)
File "C:\Python27\lib\site-packages\south\migration\base.py", line 418, in orm
return FakeORM(self.migration_class(), self.app_label())
File "C:\Python27\lib\site-packages\south\orm.py", line 46, in FakeORM
_orm_cache[args] = _FakeORM(*args)
File "C:\Python27\lib\site-packages\south\orm.py", line 125, in __init__
self.models[name] = self.make_model(app_label, model_name, data)
File "C:\Python27\lib\site-packages\south\orm.py", line 318, in make_model
field = self.eval_in_context(code, app, extra_imports)
File "C:\Python27\lib\site-packages\south\orm.py", line 236, in eval_in_context
return eval(code, globals(), fake_locals)
File "<string>", line 1
SouthFieldClass(default=datetime.datetime(2012, 9, 14, 20, 46, 3, 957000, tzinfo=<UTC>))
^
SyntaxError: invalid syntax
What's going on?
It's not letting me use schemamigration. Been searching a lot of places and deleting and resetting the database and everything, can't seem to find out what the problem is.
Problem resolved:
Didn't know about south_migrationhistory location. I was always wondering about where some extra information was hanging.
Have a look here: http://south.aeracode.org/ticket/1069
Its a bug that is fixed in newer South versions. It seems you are using an obsolete version of South(<=0.7.3)

Resources