This question already has answers here:
Django is "unable to open database file"
(8 answers)
Closed 8 years ago.
'm using sqlite3 with eclipse.
This is the first time i'm using this and when i try creating the database this is the error i get:
Traceback (most recent call last):
File "F:\New wrokspace\books\books\manage.py", line 14, in <module>
execute_manager(settings)
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 438, in execute_manager
utility.execute()
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 220, in execute
output = self.handle(*args, **options)
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 286, in handle
app_output = self.handle_app(app, **options)
File "C:\Python27\lib\site-packages\django\core\management\commands\sqlall.py", line 19, in handle_app
return u'\n'.join(sql_all(app, self.style, connections[options.get('database', DEFAULT_DB_ALIAS)])).encode('utf-8')
File "C:\Python27\lib\site-packages\django\core\management\sql.py", line 146, in sql_all
return sql_create(app, style, connection) + sql_custom(app, style, connection) + sql_indexes(app, style, connection)
File "C:\Python27\lib\site-packages\django\core\management\sql.py", line 26, in sql_create
tables = connection.introspection.table_names()
File "C:\Python27\lib\site-packages\django\db\backends\__init__.py", line 791, in table_names
cursor = self.connection.cursor()
File "C:\Python27\lib\site-packages\django\db\backends\__init__.py", line 250, in cursor
cursor = self.make_debug_cursor(self._cursor())
File "C:\Python27\lib\site-packages\django\db\backends\sqlite3\base.py", line 207, in _cursor
self.connection = Database.connect(**kwargs)
sqlite3.OperationalError: unable to open database file
Finished "F:\New wrokspace\books\books\manage.py sqlall books" execution.
Can someone tell me how to create and open sqlite3 databases on eclipse??
Thanks
To create the database with Django, you have to write your models, put applications in the settings.INSTALLED_APPS and then:
python manage.py syncdb
The sqlall command prints the CREATE TABLE and initial-data SQL statements for the given app name(s).
Related
I recently tried to run remove_stale_contenttypes in a Django 3.1 app, after deleting some custom permissions. The first time it run it warned me that some entries would be deleted, and I went ahead and entered 'yes'. The command failed with a DoesNotExist error for one of the models, and after that I can't even see the warning, it fails right away, with the following output:
Traceback (most recent call last):
File "C:\Users\Yamil\Google Drive\Proyectos\monely\manage.py", line 22, in <module>
main()
File "C:\Users\Yamil\Google Drive\Proyectos\monely\manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "C:\Users\Yamil\anaconda3\envs\monely\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
utility.execute()
File "C:\Users\Yamil\anaconda3\envs\monely\lib\site-packages\django\core\management\__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\Yamil\anaconda3\envs\monely\lib\site-packages\django\core\management\base.py", line 330, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\Yamil\anaconda3\envs\monely\lib\site-packages\django\core\management\base.py", line 371, in execute
output = self.handle(*args, **options)
File "C:\Users\Yamil\anaconda3\envs\monely\lib\site-packages\django\contrib\contenttypes\management\commands\remove_stale_contenttypes.py", line 55, in handle
collector.collect([ct])
File "C:\Users\Yamil\anaconda3\envs\monely\lib\site-packages\django\db\models\deletion.py", line 295, in collect
if sub_objs:
File "C:\Users\Yamil\anaconda3\envs\monely\lib\site-packages\django\db\models\query.py", line 291, in __bool__
self._fetch_all()
File "C:\Users\Yamil\anaconda3\envs\monely\lib\site-packages\django\db\models\query.py", line 1303, in _fetch_all
self._result_cache = list(self._iterable_class(self))
File "C:\Users\Yamil\anaconda3\envs\monely\lib\site-packages\polymorphic\query.py", line 64, in _polymorphic_iterator
real_results = self.queryset._get_real_instances(base_result_objects)
File "C:\Users\Yamil\anaconda3\envs\monely\lib\site-packages\polymorphic\query.py", line 387, in _get_real_instances
if base_object.polymorphic_ctype_id == self_model_class_id:
File "C:\Users\Yamil\anaconda3\envs\monely\lib\site-packages\django\db\models\query_utils.py", line 149, in __get__
instance.refresh_from_db(fields=[field_name])
File "C:\Users\Yamil\anaconda3\envs\monely\lib\site-packages\django\db\models\base.py", line 635, in refresh_from_db
db_instance = db_instance_qs.get()
File "C:\Users\Yamil\anaconda3\envs\monely\lib\site-packages\django\db\models\query.py", line 429, in get
raise self.model.DoesNotExist(
productos.models.DoesNotExist: Producto matching query does not exist.
Now, I noticed that the model that failed is a PolymorphicModel (django-polymorphic), but I have no idea what could be going on. The application seems to be working fine, it passes the tests. I also briefly checked the database and couldn't really find any unused contenttypes, but the command keeps failing. How can I find the root of this problem?
I have migrated from SQLite to Postgres, but now I am unable to restore my data on Postgres, i am using Django db-backup package, it is giving me this error on dbrestore command
Traceback (most recent call last):
File "C:\Users\atifs\Documents\food_deliveryapp\fooddelivery\manage.py", line 22, in <module>
main()
File "C:\Users\atifs\Documents\food_deliveryapp\fooddelivery\manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "C:\Users\atifs\Documents\food_deliveryapp\virtual-env\lib\site-packages\django\core\management\__init__.py", line 419, in execute_from_command_line
utility.execute()
File "C:\Users\atifs\Documents\food_deliveryapp\virtual-env\lib\site-packages\django\core\management\__init__.py", line 413, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\atifs\Documents\food_deliveryapp\virtual-env\lib\site-packages\django\core\management\base.py", line 354, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\atifs\Documents\food_deliveryapp\virtual-env\lib\site-packages\django\core\management\base.py", line 398, in execute
output = self.handle(*args, **options)
File "C:\Users\atifs\Documents\food_deliveryapp\virtual-env\lib\site-packages\dbbackup\management\commands\dbrestore.py", line 53, in handle
self._restore_backup()
File "C:\Users\atifs\Documents\food_deliveryapp\virtual-env\lib\site-packages\dbbackup\management\commands\dbrestore.py", line 94, in _restore_backup
self.connector.restore_dump(input_file)
File "C:\Users\atifs\Documents\food_deliveryapp\virtual-env\lib\site-packages\dbbackup\db\base.py", line 92, in restore_dump
result = self._restore_dump(dump)
File "C:\Users\atifs\Documents\food_deliveryapp\virtual-env\lib\site-packages\dbbackup\db\postgresql.py", line 56, in _restore_dump
stdout, stderr = self.run_command(cmd, stdin=dump, env=self.restore_env)
File "C:\Users\atifs\Documents\food_deliveryapp\virtual-env\lib\site-packages\dbbackup\db\postgresql.py", line 21, in run_command
return super(PgDumpConnector, self).run_command(*args, **kwargs)
File "C:\Users\atifs\Documents\food_deliveryapp\virtual-env\lib\site-packages\dbbackup\db\base.py", line 150, in run_command
raise exceptions.CommandConnectorError(
dbbackup.db.exceptions.CommandConnectorError: Error running: psql --host=localhost --port=5432 --username=postgres --no-password --set ON_ERROR_STOP=on --single-transaction postgres
ERROR: syntax error at or near "AUTOINCREMENT"
LINE 1: ...S "auth_group" ("id" integer NOT NULL PRIMARY KEY AUTOINCREM...
I am using django 2.0 with haystack+whoosh as a search. I configured as it is said in the documentation. Occurred problem is when i run ./manage.py rebuild_index it shows this error:
Traceback (most recent call last):
File "./manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "/home/zorig/.virtualenvs/ftm/lib/python3.5/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line
utility.execute()
File "/home/zorig/.virtualenvs/ftm/lib/python3.5/site-packages/django/core/management/__init__.py", line 365, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/zorig/.virtualenvs/ftm/lib/python3.5/site-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/zorig/.virtualenvs/ftm/lib/python3.5/site-packages/django/core/management/base.py", line 335, in execute
output = self.handle(*args, **options)
File "/home/zorig/.virtualenvs/ftm/lib/python3.5/site-packages/haystack/management/commands/rebuild_index.py", line 36, in handle
call_command('clear_index', **options)
File "/home/zorig/.virtualenvs/ftm/lib/python3.5/site-packages/django/core/management/__init__.py", line 133, in call_command
', '.join(sorted(valid_options)),
TypeError: Unknown option(s) for clear_index command: batchsize, workers. Valid options are: commit, help, interactive, no_color, nocommit, noinput, pythonpath, settings, skip_checks, stderr, stdout, traceback, using, verbosity, version.
after that i tried update_index it shows me this error:
File "/home/zorig/.virtualenvs/ftm/lib/python3.5/site-packages/haystack/management/commands/update_index.py", line 214, in handle self.update_backend(label, using)
File "/home/zorig/.virtualenvs/ftm/lib/python3.5/site-packages/haystack/management/commands/update_index.py", line 257, in update_backend
commit=self.commit, max_retries=self.max_retries)
File "/home/zorig/.virtualenvs/ftm/lib/python3.5/site-packages/haystack/management/commands/update_index.py", line 84, in do_update
backend.update(index, current_qs, commit=commit)
File "/home/zorig/.virtualenvs/ftm/lib/python3.5/site-packages/haystack/backends/whoosh_backend.py", line 185, in update
doc = index.full_prepare(obj)
File "/home/zorig/.virtualenvs/ftm/lib/python3.5/site-packages/haystack/indexes.py", line 208, in full_prepare
self.prepared_data = self.prepare(obj)
File "/home/zorig/.virtualenvs/ftm/lib/python3.5/site-packages/haystack/indexes.py", line 199, in prepare
self.prepared_data[field.index_fieldname] = field.prepare(obj)
File "/home/zorig/.virtualenvs/ftm/lib/python3.5/site-packages/haystack/fields.py", line 205, in prepare
return self.convert(super(CharField, self).prepare(obj))
File "/home/zorig/.virtualenvs/ftm/lib/python3.5/site-packages/haystack/fields.py", line 88, in prepare
values = self.resolve_attributes_lookup(current_objects, attrs)
File "/home/zorig/.virtualenvs/ftm/lib/python3.5/site-packages/haystack/fields.py", line 131, in resolve_attributes_lookup
values.append(current_object())
TypeError: __call__() missing 1 required keyword-only argument: 'manager'
So has anyone faced this error? Is it related to django 2.0 because i managed it work well with django 1.11.
Your installed version of Haystack does not support Django 2.0. Support for Django 2.0 was added in Haystack 2.8, which was released in March 2018.
To reset my app, I ran this:
./manage.py reset node
It is giving me this error output:
WARNING:root:The rdbms API is not available because the MySQLdb library could not be loaded.
Traceback (most recent call last):
File "./manage.py", line 11, in <module>
execute_manager(settings)
File "/home/a/mywebsites/django/seperolinux/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/home/a/mywebsites/django/seperolinux/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/a/mywebsites/django/seperolinux/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/home/a/mywebsites/django/seperolinux/django/core/management/base.py", line 220, in execute
output = self.handle(*args, **options)
File "/home/a/mywebsites/django/seperolinux/django/core/management/base.py", line 286, in handle
app_output = self.handle_app(app, **options)
File "/home/a/mywebsites/django/seperolinux/django/core/management/commands/reset.py", line 35, in handle_app
sql_list = sql_reset(app, self.style, connection)
File "/home/a/mywebsites/django/seperolinux/django/core/management/sql.py", line 107, in sql_reset
return sql_delete(app, style, connection) + sql_all(app, style, connection)
File "/home/a/mywebsites/django/seperolinux/django/core/management/sql.py", line 66, in sql_delete
table_names = connection.introspection.get_table_list(cursor)
AttributeError: 'DatabaseIntrospection' object has no attribute 'get_table_list'
How do I reset a Model in Django-nonrel?
./manage.py reset node
executes sqlreset to create DROPT TABLE and CREATE TABLE SQL
statements for the given app.
https://docs.djangoproject.com/en/1.3/ref/django-admin/#reset-appname-appname
This does not work with the App Engine Datastore, because the Datastore is schemaless so there is no need for CREATE/DROP table commands.
If you want to delete existing model from the datastore, you can use the App Engine Development Console to delete all entities of the model (just make sure you use the correct port when accessing the Development Console) .
When I try to install ByteFlow on my Windows development machine, I got the following MySQL error, and I don't know what to do, please give me some suggestion. Thank you so much!!!
E:\byteflow-5b6d964917b5>manage.py syncdb
!!! Read about DEBUG in settings_local.py and then remove me !!!
!!! Read about DEBUG in settings_local.py and then remove me !!!
J:\Program Files\Python26\lib\site-packages\MySQLdb\converters.py:37: DeprecationWarning: the sets module is deprecated
from sets import BaseSet, Set
Creating table auth_permission
Creating table auth_group
Creating table auth_user
Creating table auth_message
Creating table django_content_type
Creating table django_session
Creating table django_site
Creating table django_admin_log
Creating table django_flatpage
Creating table actionrecord
Creating table blog_post
Traceback (most recent call last):
File "E:\byteflow-5b6d964917b5\manage.py", line 11, in <module>
execute_manager(settings)
File "J:\Program Files\Python26\lib\site-packages\django\core\management\__init__.py", line 362, in execute_manager
utility.execute()
File "J:\Program Files\Python26\lib\site-packages\django\core\management\__init__.py", line 303, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "J:\Program Files\Python26\lib\site-packages\django\core\management\base.py", line 195, in run_from_argv
self.execute(*args, **options.__dict__)
File "J:\Program Files\Python26\lib\site-packages\django\core\management\base.py", line 222, in execute
output = self.handle(*args, **options)
File "J:\Program Files\Python26\lib\site-packages\django\core\management\base.py", line 351, in handle
return self.handle_noargs(**options)
File "J:\Program Files\Python26\lib\site-packages\django\core\management\commands\syncdb.py", line 78, in handle_noargs
cursor.execute(statement)
File "J:\Program Files\Python26\lib\site-packages\django\db\backends\util.py", line 19, in execute
return self.cursor.execute(sql, params)
File "J:\Program Files\Python26\lib\site-packages\django\db\backends\mysql\base.py", line 84, in execute
return self.cursor.execute(query, args)
File "J:\Program Files\Python26\lib\site-packages\MySQLdb\cursors.py", line 166, in execute
self.errorhandler(self, exc, value)
File "J:\Program Files\Python26\lib\site-packages\MySQLdb\connections.py", line 35, in defaulterrorhandler
raise errorclass, errorvalue
_mysql_exceptions.OperationalError: (1071, 'Specified key was too long; max key length is 767 bytes')
Try to change MySql default storage engine to MyISAM.