I've created a custom management command for django-admin.py, but the
sql execution (using statements created by sql_delete) keeps failing
on django.db.utils.DatabaseError: unrecognized token: " "
I'm afraid I'm not sure what's wrong. I'm currently thinking it's some
kind of encoding problem, but I can't seem to pinpoint the cause.
The custom command code is as follows:
from optparse import make_option
from django.db import connection, transaction, connections,
DEFAULT_DB_ALIAS
from django.core.management.sql import sql_delete
from django.core.management.base import AppCommand
class Command(AppCommand):
option_list = AppCommand.option_list + (
make_option('--database', action='store', dest='database',
default=DEFAULT_DB_ALIAS, help='Nominates a database to
print the '
'SQL for. Defaults to the "default" database.'),
)
def handle_app(self, app, **options):
drop_statements = sql_delete(app, self.style,
connections[options.get('database', DEFAULT_DB_ALIAS)])
for statement in drop_statements:
statement = statement
cursor = connection.cursor()
cursor.execute(statement)
transaction.commit_unless_managed()
The error is:
python manage.py drop_some_tables blog
Traceback (most recent call last):
File "manage.py", line 11, in <module>
execute_manager(settings)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/
__init__.py", line 438, in execute_manager
utility.execute()
File "/usr/local/lib/python2.6/dist-packages/django/core/management/
__init__.py", line 379, 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 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/
base.py", line 218, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/
base.py", line 282, in handle
app_output = self.handle_app(app, **options)
File "/home/mathias/Documents/I2P/i2p.www.jinja2/www_django/../
www_django/i2p_magic/management/commands/drop_some_tables.py", line
18, in handle_app
cursor.execute(statement)
File "/usr/local/lib/python2.6/dist-packages/django/db/backends/
util.py", line 15, in execute
return self.cursor.execute(sql, params)
File "/usr/local/lib/python2.6/dist-packages/django/db/backends/
sqlite3/base.py", line 200, in execute
return Database.Cursor.execute(self, query, params)
django.db.utils.DatabaseError: unrecognized token: " "
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
No comments:
Post a Comment