Django-nonrel: Syntax to Reset an App - django

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) .

Related

DeserializationError when adding fixture on server (loaddata)

I am trying to add my data to database in my server. I use exactly the same JSON file in my local machine and it works. But when I do the same in server it gives me Deserialization Error.
The JSON file is so big that I can't show it here but I am sure there is no typo.
I did all migrations and database works - I can add object from admin dashboard. How can I solve this error?
The error I get:
Traceback (most recent call last):
File "/home/testuser/myprojectt/myvenv/lib/python3.8/site-packages/django/core/serializers/json.py", line 69, in Deserializer
objects = json.loads(stream_or_string)
File "/usr/lib/python3.8/json/__init__.py", line 357, in loads
return _default_decoder.decode(s)
File "/usr/lib/python3.8/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python3.8/json/decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
main()
File "manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/home/testuser/myprojectt/myvenv/lib/python3.8/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/home/testuser/myprojectt/myvenv/lib/python3.8/site-packages/django/core/management/__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/testuser/myprojectt/myvenv/lib/python3.8/site-packages/django/core/management/base.py", line 330, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/testuser/myprojectt/myvenv/lib/python3.8/site-packages/django/core/management/base.py", line 371, in execute
output = self.handle(*args, **options)
File "/home/testuser/myprojectt/myvenv/lib/python3.8/site-packages/django/core/management/commands/loaddata.py", line 72, in handle
self.loaddata(fixture_labels)
File "/home/testuser/myprojectt/myvenv/lib/python3.8/site-packages/django/core/management/commands/loaddata.py", line 114, in loaddata
self.load_label(fixture_label)
File "/home/testuser/myprojectt/myvenv/lib/python3.8/site-packages/django/core/management/commands/loaddata.py", line 172, in load_label
for obj in objects:
File "/home/testuser/myprojectt/myvenv/lib/python3.8/site-packages/django/core/serializers/json.py", line 74, in Deserializer
raise DeserializationError() from exc
django.core.serializers.base.DeserializationError: Problem installing fixture '/home/testuser/myprojectt/myprojectt/articles/fixtures/article.json':
Checked the JSON again and again but it still working on local but the same error on server.
I am using Ubuntu on the server. And didn't have git-lfs installed. To solve this issue:
Install it with sudo apt-get install git-lfs.
Then run git lfs pull on project directory.
And then I managed to work with the JSON data as I wanted.

Unable to rebuild index in django haystack

I am trying to run manage.py rebuild_index but getting below error.
`(django_project)deep#deep-ThinkPad-Edge:~/doroko$ python manage.py rebuild_index No handlers could be found for logger "django_facebook.models" /home/deep/.virtualenvs/django_project/local/lib/python2.7/site-packages/django/utils/image.py:150: RemovedInDjango18Warning: Support for the PIL will be removed in Django 1.8. Please uninstall it & install Pillow instead. RemovedInDjango18Warning
System check identified some issues:
WARNINGS: ?: (1_6.W001) Some project unittests may not execute as expected. HINT: Django 1.6 introduced a new default test runner. It looks like this project was generated using Django 1.5 or earlier. You should ensure your tests are all running & behaving as expected. See https://docs.djangoproject.com/en/dev/releases/1.6/#new-test-runner for more information. System check identified some issues:
WARNINGS: ?: (1_6.W001) Some project unittests may not execute as expected. HINT: Django 1.6 introduced a new default test runner. It looks like this project was generated using Django 1.5 or earlier. You should ensure your tests are all running & behaving as expected. See https://docs.djangoproject.com/en/dev/releases/1.6/#new-test-runner for more information.
WARNING: This will irreparably remove EVERYTHING from your search index in connection 'default'. Your choices after this are to restore from backups or rebuild via the `rebuild_index` command. Are you sure you wish to continue? [y/N] y Removing all documents from your index because you said so. Failed to clear Elasticsearch index: ConnectionError(('Connection aborted.', error(111, 'Connection refused'))) caused by: ProtocolError(('Connection aborted.', error(111, 'Connection refused'))) All documents removed. System check identified some issues:
WARNINGS: ?: (1_6.W001) Some project unittests may not execute as expected. HINT: Django 1.6 introduced a new default test runner. It looks like this project was generated using Django 1.5 or earlier. You should ensure your tests are all running & behaving as expected. See https://docs.djangoproject.com/en/dev/releases/1.6/#new-test-runner for more information. Indexing 34 wishs ERROR:root:Error updating feed using default Traceback (most recent call last): File "/home/deep/.virtualenvs/django_project/local/lib/python2.7/site-packages/haystack/management/commands/update_index.py", line 189, in handle_label
self.update_backend(label, using) File "/home/deep/.virtualenvs/django_project/local/lib/python2.7/site-packages/haystack/management/commands/update_index.py", line 234, in update_backend
do_update(backend, index, qs, start, end, total, self.verbosity) File "/home/deep/.virtualenvs/django_project/local/lib/python2.7/site-packages/haystack/management/commands/update_index.py", line 89, in do_update
backend.update(index, current_qs) File "/home/deep/.virtualenvs/django_project/local/lib/python2.7/site-packages/haystack/backends/elasticsearch_backend.py", line 164, in update
prepped_data = index.full_prepare(obj) File "/home/deep/.virtualenvs/django_project/local/lib/python2.7/site-packages/haystack/indexes.py", line 207, in full_prepare
self.prepared_data = self.prepare(obj) File "/home/deep/doroko/feed/search_indexes.py", line 16, in prepare
data = super(feedIndex, self).prepare(obj) File "/home/deep/.virtualenvs/django_project/local/lib/python2.7/site-packages/haystack/indexes.py", line 198, in prepare
self.prepared_data[field.index_fieldname] = field.prepare(obj) File "/home/deep/.virtualenvs/django_project/local/lib/python2.7/site-packages/haystack/fields.py", line 159, in prepare
return self.convert(super(CharField, self).prepare(obj)) File "/home/deep/.virtualenvs/django_project/local/lib/python2.7/site-packages/haystack/fields.py", line 165, in convert
return six.text_type(value) File "/home/deep/.virtualenvs/django_project/local/lib/python2.7/site-packages/django/db/models/manager.py", line 81, in __str__
in opts.concrete_managers + opts.abstract_managers StopIteration Traceback (most recent call last): File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv) File "/home/deep/.virtualenvs/django_project/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute() File "/home/deep/.virtualenvs/django_project/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv) File "/home/deep/.virtualenvs/django_project/local/lib/python2.7/site-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **options.__dict__) File "/home/deep/.virtualenvs/django_project/local/lib/python2.7/site-packages/django/core/management/base.py", line 338, in execute
output = self.handle(*args, **options) File "/home/deep/.virtualenvs/django_project/local/lib/python2.7/site-packages/haystack/management/commands/rebuild_index.py", line 16, in handle
call_command('update_index', **options) File "/home/deep/.virtualenvs/django_project/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 115, in call_command
return klass.execute(*args, **defaults) File "/home/deep/.virtualenvs/django_project/local/lib/python2.7/site-packages/django/core/management/base.py", line 338, in execute
output = self.handle(*args, **options) File "/home/deep/.virtualenvs/django_project/local/lib/python2.7/site-packages/haystack/management/commands/update_index.py", line 184, in handle
return super(Command, self).handle(*items, **options) File "/home/deep/.virtualenvs/django_project/local/lib/python2.7/site-packages/django/core/management/base.py", line 503, in handle
label_output = self.handle_label(label, **options) File "/home/deep/.virtualenvs/django_project/local/lib/python2.7/site-packages/haystack/management/commands/update_index.py", line 189, in handle_label
self.update_backend(label, using) File "/home/deep/.virtualenvs/django_project/local/lib/python2.7/site-packages/haystack/management/commands/update_index.py", line 234, in update_backend
do_update(backend, index, qs, start, end, total, self.verbosity) File "/home/deep/.virtualenvs/django_project/local/lib/python2.7/site-packages/haystack/management/commands/update_index.py", line 89, in do_update
backend.update(index, current_qs) File "/home/deep/.virtualenvs/django_project/local/lib/python2.7/site-packages/haystack/backends/elasticsearch_backend.py", line 164, in update
prepped_data = index.full_prepare(obj) File "/home/deep/.virtualenvs/django_project/local/lib/python2.7/site-packages/haystack/indexes.py", line 207, in full_prepare
self.prepared_data = self.prepare(obj) File "/home/deep/doroko/feed/search_indexes.py", line 16, in prepare
data = super(feedIndex, self).prepare(obj) File "/home/deep/.virtualenvs/django_project/local/lib/python2.7/site-packages/haystack/indexes.py", line 198, in prepare
self.prepared_data[field.index_fieldname] = field.prepare(obj) File "/home/deep/.virtualenvs/django_project/local/lib/python2.7/site-packages/haystack/fields.py", line 159, in prepare
return self.convert(super(CharField, self).prepare(obj)) File "/home/deep/.virtualenvs/django_project/local/lib/python2.7/site-packages/haystack/fields.py", line 165, in convert
return six.text_type(value) File "/home/deep/.virtualenvs/django_project/local/lib/python2.7/site-packages/django/db/models/manager.py", line 81, in __str__
in opts.concrete_managers + opts.abstract_managers StopIteration`
This is the search_indexes.py file for model.
import datetime
from haystack import indexes
from feed.models import Wish
class feedIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, use_template=True)
wish_text = indexes.CharField(model_attr='wish_text',null=True)
tags = indexes.CharField(model_attr='tags')
added = indexes.DateTimeField(model_attr='added')
def get_model(self):
return Wish
def prepare_wish_text(self, obj):
return "Wish"
def prepare(self, obj):
data = super(feedIndex, self).prepare(obj)
data["_boost"] = 1.5
return data
Following are versions used :
Django==1.7.6
django-haystack==2.3.1
elasticsearch==1.4.0
pyelasticsearch==0.5
Testing seems to suggest this comes up if a search template is incorrectly configured.
Double check all the fields in your search template and find the incorrect one and the issue should resolve.
https://groups.google.com/forum/#!topic/django-haystack/InXrimOyHtQ

Unable to open sqlite3 database file [duplicate]

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).

django/postgres: Transaction managed block ended with pending COMMIT/ROLLBACK

I want to run manage.py sqldiff myapp (command from django extension), but I get the following error:
Traceback (most recent call last):
File "manage.py", line 11, in <module>
execute_manager(settings)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/usr/local/lib/python2.7/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.7/dist-packages/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 220, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python2.7/dist-packages/django_extensions/management/commands/sqldiff.py", line 596, in handle
sqldiff_instance.find_differences()
File "/usr/local/lib/python2.7/dist-packages/django/db/transaction.py", line 222, in inner
self.__exit__(None, None, None)
File "/usr/local/lib/python2.7/dist-packages/django/db/transaction.py", line 207, in __exit__
self.exiting(exc_value, self.using)
File "/usr/local/lib/python2.7/dist-packages/django/db/transaction.py", line 302, in exiting
leave_transaction_management(using=using)
File "/usr/local/lib/python2.7/dist-packages/django/db/transaction.py", line 56, in leave_transaction_management
connection.leave_transaction_management()
File "/usr/local/lib/python2.7/dist-packages/django/db/backends/__init__.py", line 115, in leave_transaction_management
raise TransactionManagementError("Transaction managed block ended with "
django.db.transaction.TransactionManagementError: Transaction managed block ended with pending COMMIT/ROLLBACK
manage.py runserver, shell, shell_plus all work fine, but the sqldiff command chokes. I have tried:
restart postgres server
manually connect to postgres from shell via psycopg2, ran
connection.rollback(), and connection.commit()
but the error persists.
Any ideas on what can be done are welcome!
Cheers,
Hoff
I updated an issue with sqldiff causing similar problems. Your best bet is probably to obtain django-extensions from the github repository and do a bit of investigation. Edit sqldiff.py and comment out the transaction code decorating the find_differences method:
# #transaction.commit_manually
def find_differences(self):
...
# transaction.rollback() # reset transaction
...
# transaction.commit()
Now your real problem should be revealed, no longer masked by the transaction exception.

ByteFlow installation Error on Windows

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.