South not migrating taggit.managers - django

I just added tags=TaggableManager() in my models.py file. And i initiated to run python manage.py schemamigration myapp --initial it shows below error
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 392, 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 242, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 285, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python2.7/dist-packages/South-0.8.1-py2.7.egg/south/management/commands/schemamigration.py", line 151, in handle
for action_name, params in change_source.get_changes():
File "/usr/local/lib/python2.7/dist-packages/South-0.8.1-py2.7.egg/south/creator/changes.py", line 460, in get_changes
model_defs = freeze_apps([self.migrations.app_label()])
File "/usr/local/lib/python2.7/dist-packages/South-0.8.1-py2.7.egg/south/creator/freezer.py", line 32, in freeze_apps
frozen_models.update(model_dependencies(model))
File "/usr/local/lib/python2.7/dist-packages/South-0.8.1-py2.7.egg/south/creator/freezer.py", line 96, in model_dependencies
depends.update(field_dependencies(field, checked_models))
File "/usr/local/lib/python2.7/dist-packages/South-0.8.1-py2.7.egg/south/creator/freezer.py", line 132, in field_dependencies
value = get_attribute(field, attrname)
File "/usr/local/lib/python2.7/dist-packages/South-0.8.1-py2.7.egg/south/utils/__init__.py", line 38, in get_attribute
value = getattr(value, part)
AttributeError: 'TaggableManager' object has no attribute 'primary_key'
In south migration tutorials itself they said to add below two lines. I did
from south.modelsinspector import add_ignored_fields
add_ignored_fields(["^taggit\.managers"])
Nothing happened. But the same error coming again

Related

Testing Django in a Virtual Environment

I have a Django project setup under virtualenv, and have a empty tests.py under the project folder.
When I do "python manage.py test", I am getting the following error:
Traceback (most recent call last):
File "manage.py", line 12, in <module>
execute_from_command_line(sys.argv)
File "/Users/dj_prj/dj_prj/env/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/Users/dj_prj/dj_prj/env/lib/python2.7/site-packages/django/core/management/__init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/dj_prj/dj_prj/env/lib/python2.7/site-packages/django/core/management/commands/test.py", line 50, in run_from_argv
super(Command, self).run_from_argv(argv)
File "/Users/dj_prj/dj_prj/env/lib/python2.7/site-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Users/dj_prj/dj_prj/env/lib/python2.7/site-packages/django/core/management/commands/test.py", line 71, in execute
super(Command, self).execute(*args, **options)
File "/Users/dj_prj/dj_prj/env/lib/python2.7/site-packages/django/core/management/base.py", line 338, in execute
output = self.handle(*args, **options)
File "/Users/dj_prj/dj_prj/env/lib/python2.7/site-packages/django/core/management/commands/test.py", line 88, in handle
failures = test_runner.run_tests(test_labels)
File "/Users/dj_prj/dj_prj/oicms/test/oicms_test_runner.py", line 209, in run_tests
suite = self.build_suite(test_labels, extra_tests)
File "/Users/dj_prj/dj_prj/oicms/test/oicms_test_runner.py", line 150, in build_suite
tests = self.test_loader.discover(start_dir=label, **kwargs)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/loader.py", line 206, in discover
tests = list(self._find_tests(start_dir, pattern))
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/loader.py", line 267, in _find_tests
raise ImportError(msg % (mod_name, module_dir, expected_dir))
ImportError: 'tests' module incorrectly imported from '/Users/dj_prj/dj_prj/dj_prj'. Expected '/Users/dj_prj/dj_prj/'. Is this module globally installed?
What is your environment?
Your problem may be related to this one:
Django test runner fails in virtualenv on Ubuntu

API Test Case - 'module' object has no attribute

$ python manage.py test homepage.shortlistedlist
When i run above django rest framework testcase file, i met below error, kindly help me to solve this problem,
(py3.4)testuser#testuser-To:~/projects/testfile/testfile$ python manage.py test homepage.compareproperties --settings=testfile.settings.test
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/testuser/envs/testfile/lib/python3.4/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/home/testuser/envs/testfile/lib/python3.4/site-packages/django/core/management/__init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/testuser/envs/testfile/lib/python3.4/site-packages/django/core/management/commands/test.py", line 50, in run_from_argv
super(Command, self).run_from_argv(argv)
File "/home/testuser/envs/testfile/lib/python3.4/site-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "/home/testuser/envs/testfile/lib/python3.4/site-packages/django/core/management/commands/test.py", line 71, in execute
super(Command, self).execute(*args, **options)
File "/home/testuser/envs/testfile/lib/python3.4/site-packages/django/core/management/base.py", line 338, in execute
output = self.handle(*args, **options)
File "/home/testuser/envs/testfile/lib/python3.4/site-packages/django/core/management/commands/test.py", line 88, in handle
failures = test_runner.run_tests(test_labels)
File "/home/testuser/envs/testfile/lib/python3.4/site-packages/django/test/runner.py", line 146, in run_tests
suite = self.build_suite(test_labels, extra_tests)
File "/home/testuser/envs/testfile/lib/python3.4/site-packages/django/test/runner.py", line 95, in build_suite
tests = self.test_loader.discover(start_dir=label, **kwargs)
File "/usr/lib/python3.4/unittest/loader.py", line 255, in discover
self._get_directory_containing_module(top_part)
File "/usr/lib/python3.4/unittest/loader.py", line 269, in _get_directory_containing_module
full_path = os.path.abspath(module.__file__)
AttributeError: 'module' object has no attribute '__file__'
Thanks In Advance,
I was able to solve this by adding an empty __init__.py to the root of my project.
I think the clue is the get_directory_containing_module() call - without __init__.py, it doesn't see the directory as a module.

How to run South migrations for two (or multiple) Django test databases?

In my apps settings.py file (then made available in django.conf.settings) I have specified:
DATABASES = {'default': dj_database_url.parse(os.environ['DATABASE']),
'secondary': dj_database_url.parse(os.environ['SECONDARY_DATABASE'])}
SOUTH_TESTS_MIGRATE = True
But running my tests using ./manage.py test app_name runs the migrations for the default database and creates some of the tables for the secondary database before failing with:
Creating test database for alias 'secondary' ('test_secondary')...
Syncing...
Creating tables ...
Creating table auth_permission
...
Creating table django_admin_log
Installing custom SQL ...
Installing indexes ...
Migrating...
Traceback (most recent call last):
File "./manage.py", line 18, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line
utility.execute()
File "/usr/local/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 381, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/venv/local/lib/python2.7/site-packages/django/core/management/commands/test.py", line 49, in run_from_argv
super(Command, self).run_from_argv(argv)
File "/usr/local/venv/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/venv/local/lib/python2.7/site-packages/django/core/management/base.py", line 232, in execute
output = self.handle(*args, **options)
File "/usr/local/venv/local/lib/python2.7/site-packages/django/test/simple.py", line 381, in run_tests
old_config = self.setup_databases()
File "/usr/local/venv/local/lib/python2.7/site-packages/django/test/simple.py", line 317, in setup_databases
self.verbosity, autoclobber=not self.interactive)
File "/usr/local/venv/local/lib/python2.7/site-packages/south/hacks/django_1_0.py", line 100, in wrapper
f(*args, **kwargs)
File "/usr/local/venv/local/lib/python2.7/site-packages/django/db/backends/creation.py", line 271, in create_test_db
load_initial_data=False)
File "/usr/local/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 149, in call_command
return klass.execute(*args, **defaults)
File "/usr/local/venv/local/lib/python2.7/site-packages/django/core/management/base.py", line 232, in execute
output = self.handle(*args, **options)
File "/usr/local/venv/local/lib/python2.7/site-packages/django/core/management/base.py", line 371, in handle
return self.handle_noargs(**options)
File "/usr/local/venv/local/lib/python2.7/site-packages/south/management/commands/syncdb.py", line 99, in handle_noargs
management.call_command('migrate', **options)
File "/usr/local/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 149, in call_command
return klass.execute(*args, **defaults)
File "/usr/local/venv/local/lib/python2.7/site-packages/django/core/management/base.py", line 232, in execute
output = self.handle(*args, **options)
File "/usr/local/venv/local/lib/python2.7/site-packages/south/management/commands/migrate.py", line 108, in handle
ignore_ghosts = ignore_ghosts,
File "/usr/local/venv/local/lib/python2.7/site-packages/south/migration/__init__.py", line 171, in migrate_app
south.db.db = south.db.dbs[database]
KeyError: 'secondary'

Repeating SYNCDB produces different outcomes?

When I ran syncdb it gave me a MySQL 150 error, probably related to a FK. However, when I repeatedly run syncdb, it eventually works (the entire trace below). Why is this occurring?
david-MacBook-Pro$ syncdb
Creating tables ...
Creating table jobs_company
Creating table jobs_job
Traceback (most recent call last):
File "manage.py", line 14, in <module>
execute_manager(settings)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 220, in execute
output = self.handle(*args, **options)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 351, in handle
return self.handle_noargs(**options)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/commands/syncdb.py", line 101, in handle_noargs
cursor.execute(statement)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/backends/util.py", line 34, in execute
return self.cursor.execute(sql, params)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 86, in execute
return self.cursor.execute(query, args)
File "build/bdist.macosx-10.6-intel/egg/MySQLdb/cursors.py", line 174, in execute
File "build/bdist.macosx-10.6-intel/egg/MySQLdb/connections.py", line 36, in defaulterrorhandler
_mysql_exceptions.OperationalError: (1005, "Can't create table 'david542.#sql-2c3_57e' (errno: 150)")
david-MacBook-Pro:$ syncdb
Creating tables ...
Creating table jobs_jobposition
Creating table jobs_externaljob
Creating table jobs_externalsite
Creating table jobs_sitevisit
Traceback (most recent call last):
File "manage.py", line 14, in <module>
execute_manager(settings)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 220, in execute
output = self.handle(*args, **options)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 351, in handle
return self.handle_noargs(**options)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/commands/syncdb.py", line 101, in handle_noargs
cursor.execute(statement)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/backends/util.py", line 34, in execute
return self.cursor.execute(sql, params)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 86, in execute
return self.cursor.execute(query, args)
File "build/bdist.macosx-10.6-intel/egg/MySQLdb/cursors.py", line 174, in execute
File "build/bdist.macosx-10.6-intel/egg/MySQLdb/connections.py", line 36, in defaulterrorhandler
_mysql_exceptions.OperationalError: (1005, "Can't create table 'david542.#sql-2c3_57f' (errno: 150)")
david-MacBook-Pro$ syncdb
Creating tables ...
Creating table jobs_application
Traceback (most recent call last):
File "manage.py", line 14, in <module>
execute_manager(settings)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 220, in execute
output = self.handle(*args, **options)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 351, in handle
return self.handle_noargs(**options)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/commands/syncdb.py", line 101, in handle_noargs
cursor.execute(statement)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/backends/util.py", line 34, in execute
return self.cursor.execute(sql, params)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 86, in execute
return self.cursor.execute(query, args)
File "build/bdist.macosx-10.6-intel/egg/MySQLdb/cursors.py", line 174, in execute
File "build/bdist.macosx-10.6-intel/egg/MySQLdb/connections.py", line 36, in defaulterrorhandler
_mysql_exceptions.OperationalError: (1005, "Can't create table 'david542.#sql-2c3_580' (errno: 150)")
david-MacBook-Pro$ syncdb
Creating tables ...
Installing custom SQL ...
Installing indexes ...
No fixtures found.
And it works?
It's working because the FKs aren't being created. Analyze the generated SQL to verify why the errors are occurring, and reorder settings.INSTALLED_APPS as appropriate.

Haystack + Whoosh IndexError: Index was created on an architecture with different data sizes

When rebuilding my indices via ./manage.py rebuild_index I get this error:
Traceback (most recent call last):
File "manage.py", line 11, in <module>
execute_manager(settings)
File "/Library/Python/2.6/site-packages/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/Library/Python/2.6/site-packages/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Python/2.6/site-packages/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Library/Python/2.6/site-packages/django/core/management/base.py", line 218, in execute
output = self.handle(*args, **options)
File "/Library/Python/2.6/site-packages/haystack/management/commands/rebuild_index.py", line 13, in handle
call_command('clear_index', **options)
File "/Library/Python/2.6/site-packages/django/core/management/__init__.py", line 166, in call_command
return klass.execute(*args, **defaults)
File "/Library/Python/2.6/site-packages/django/core/management/base.py", line 218, in execute
output = self.handle(*args, **options)
File "/Library/Python/2.6/site-packages/haystack/management/commands/clear_index.py", line 38, in handle
sb.clear()
File "/Library/Python/2.6/site-packages/haystack/backends/whoosh_backend.py", line 197, in clear
self.setup()
File "/Library/Python/2.6/site-packages/haystack/backends/whoosh_backend.py", line 105, in setup
self.index = self.storage.open_index(schema=self.schema)
File "/Library/Python/2.6/site-packages/Whoosh-0.3.18-py2.6.egg/whoosh/filedb/filestore.py", line 48, in open_index
File "/Library/Python/2.6/site-packages/Whoosh-0.3.18-py2.6.egg/whoosh/filedb/fileindex.py", line 94, in __init__
File "/Library/Python/2.6/site-packages/Whoosh-0.3.18-py2.6.egg/whoosh/filedb/fileindex.py", line 173, in _read
IndexError: Index was created on an architecture with different data sizes
You have probably downgraded from whoosh 1.0.0 to 0.3.18, but there are some buggy index files already created at the path you defined by HAYSTACK_WHOOSH_PATH. Just make that directory empty and try again.