Django South migration error - django

I am getting an error trying to apply a first South migration. I have tried various suggestions (like removing .pyc files in the migrations folder, converting the app as well as trying to start it afresh, other fiddles). Can anyone here suggest what I might do? Thanks
(env)~/code/django/ssc/dev/ssc/ssc> python manage.py migrate
Traceback (most recent call last):
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 443, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/dist-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/dist-packages/django/core/management/base.py", line 196, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 232, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python2.7/dist-packages/south/management/commands/migrate.py", line 108, in handle
ignore_ghosts = ignore_ghosts,
File "/usr/local/lib/python2.7/dist-packages/south/migration/__init__.py", line 166, in migrate_app
Migrations.calculate_dependencies()
File "/usr/local/lib/python2.7/dist-packages/south/migration/base.py", line 228, in calculate_dependencies
migration.calculate_dependencies()
File "/usr/local/lib/python2.7/dist-packages/south/migration/base.py", line 362, in calculate_dependencies
for migration in self._get_dependency_objects("depends_on"):
File "/usr/local/lib/python2.7/dist-packages/south/migration/base.py", line 342, in _get_dependency_objects
for app, name in getattr(self.migration_class(), attrname, []):
File "/usr/local/lib/python2.7/dist-packages/south/migration/base.py", line 314, in migration_class
return self.migration().Migration
AttributeError: 'module' object has no attribute 'Migration'
(env)~/code/django/ssc/dev/ssc/ssc> python manage.py convert_to_south crewcal
This application is already managed by South.
(env)~/code/django/ssc/dev/ssc/ssc> python manage.py migrateTraceback (most recent call last):
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 443, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/dist-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/dist-packages/django/core/management/base.py", line 196, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 232, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python2.7/dist-packages/south/management/commands/migrate.py", line 108, in handle
ignore_ghosts = ignore_ghosts,
File "/usr/local/lib/python2.7/dist-packages/south/migration/__init__.py", line 166, in migrate_app
Migrations.calculate_dependencies()
File "/usr/local/lib/python2.7/dist-packages/south/migration/base.py", line 228, in calculate_dependencies
migration.calculate_dependencies()
File "/usr/local/lib/python2.7/dist-packages/south/migration/base.py", line 362, in calculate_dependencies
for migration in self._get_dependency_objects("depends_on"):
File "/usr/local/lib/python2.7/dist-packages/south/migration/base.py", line 342, in _get_dependency_objects
for app, name in getattr(self.migration_class(), attrname, []):
File "/usr/local/lib/python2.7/dist-packages/south/migration/base.py", line 314, in migration_class
return self.migration().Migration
AttributeError: 'module' object has no attribute 'Migration'

In my case the AttributeError: 'module' object has no attribute 'Migration' error was simply a matter of having an extra .py file in my migrations folder.
I had an extra utilities module in my migrations directory which caused South to choke. Moving the module into a different directory (above my apps migrations directory) solved the problem for me.

Maybe a bit late, but still...
Is it possible you have any other package (folder with __init__.py) in your migration package and it interferes with the structure?

Wow. I was getting the AttributeError: 'module' object has no attribute 'Migration' error for a completely different reason than the above answers.
I had a migration file which had a bad indent:
class Migration(SchemaMigration):
def forwards(self, orm):
#
def backwards(self, orm):
#
models = {...}
As opposed to ...
class Migration(SchemaMigration):
def forwards(self, orm):
#
def backwards(self, orm):
#
models = {...}
I don't know why I had that but when I fixed that the error was gone.

Related

Makemigrations in Django

I cannot "makemigrations" in my Django project. When I try to do
"python manage.py makemigrations"
It shows the following
Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "/home/ani/Desktop/Backup/venv/lib/python3.7/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/home/ani/Desktop/Backup/venv/lib/python3.7/site-packages/django/core/management/__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/ani/Desktop/Backup/venv/lib/python3.7/site-packages/django/core/management/base.py", line 316, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/ani/Desktop/Backup/venv/lib/python3.7/site-packages/django/core/management/base.py", line 353, in execute
output = self.handle(*args, **options)
File "/home/ani/Desktop/Backup/venv/lib/python3.7/site-packages/django/core/management/base.py", line 83, in wrapped
res = handle_func(*args, **kwargs)
File "/home/ani/Desktop/Backup/venv/lib/python3.7/site-packages/django/core/management/commands/makemigrations.py", line 89, in handle
loader = MigrationLoader(None, ignore_no_migrations=True)
File "/home/ani/Desktop/Backup/venv/lib/python3.7/site-packages/django/db/migrations/loader.py", line 49, in __init__
self.build_graph()
File "/home/ani/Desktop/Backup/venv/lib/python3.7/site-packages/django/db/migrations/loader.py", line 273, in build_graph
raise exc
File "/home/ani/Desktop/Backup/venv/lib/python3.7/site-packages/django/db/migrations/loader.py", line 247, in build_graph
self.graph.validate_consistency()
File "/home/ani/Desktop/Backup/venv/lib/python3.7/site-packages/django/db/migrations/graph.py", line 243, in validate_consistency
[n.raise_error() for n in self.node_map.values() if isinstance(n, DummyNode)]
File "/home/ani/Desktop/Backup/venv/lib/python3.7/site-packages/django/db/migrations/graph.py", line 243, in <listcomp>
[n.raise_error() for n in self.node_map.values() if isinstance(n, DummyNode)]
File "/home/ani/Desktop/Backup/venv/lib/python3.7/site-packages/django/db/migrations/graph.py", line 96, in raise_error
raise NodeNotFoundError(self.error_message, self.key, origin=self.origin)
django.db.migrations.exceptions.NodeNotFoundError: Migration djoser.0001_initial dependencies reference nonexistent parent node ('auth', '0011_update_proxy_permissions')
I tried installing mysqlclient and creating the database all over again but then it doesn't work at all.
Your migrations directory is broken. Django creates migrations files for each migration (each time you type makemigration.
Currently, one of your migrations file has something like:
dependencies = [
('accounts', '0011_update_proxy_permissions'),
]
And migrations/0011_update_proxy_permissions.py doesn't exist. You need either edit this migration manually or remove everything in migrations directory and run makemigrations from scratch. If you remove migrations you will also need to drop the database so django would create it from the scratch.
There're a lot of articles out there that would help you to investigate your issue further. Like this one

Django CMS migrate from SQLite to PostgreSQL

I'm developing a project with Django CMS 3.5. I used SQLite for development and have data in there. Now I'm trying to migrate to PostgreSQL. My steps so far:
python manage.py dumpdata --natural-primary --natural-foreign > dump.json
Switching to production settings
python manage.py migrate
TRUNCATE django_content_type CASCADE;
python manage.py loaddata dump.json
But I encounter the next error:
Traceback (most recent call last):
File "/home/webmaster/tc56/env/lib/python3.6/site-packages/django/db/models/fields/related_descriptors.py", line 178, in __get__
rel_obj = getattr(instance, self.cache_name)
AttributeError: 'Page' object has no attribute '_node_cache'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/home/webmaster/tc56/env/lib/python3.6/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
utility.execute()
File "/home/webmaster/tc56/env/lib/python3.6/site-packages/django/core/management/__init__.py", line 356, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/webmaster/tc56/env/lib/python3.6/site-packages/django/core/management/base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/webmaster/tc56/env/lib/python3.6/site-packages/django/core/management/base.py", line 330, in execute
output = self.handle(*args, **options)
File "/home/webmaster/tc56/env/lib/python3.6/site-packages/django/core/management/commands/loaddata.py", line 69, in handle
self.loaddata(fixture_labels)
File "/home/webmaster/tc56/env/lib/python3.6/site-packages/django/core/management/commands/loaddata.py", line 109, in loaddata
self.load_label(fixture_label)
File "/home/webmaster/tc56/env/lib/python3.6/site-packages/django/core/management/commands/loaddata.py", line 175, in load_label
obj.save(using=self.using)
File "/home/webmaster/tc56/env/lib/python3.6/site-packages/django/core/serializers/base.py", line 205, in save
models.Model.save_base(self.object, using=using, raw=True, **kwargs)
File "/home/webmaster/tc56/env/lib/python3.6/site-packages/django/db/models/base.py", line 833, in save_base
update_fields=update_fields,
File "/home/webmaster/tc56/env/lib/python3.6/site-packages/django/dispatch/dispatcher.py", line 193, in send
for receiver in self._live_receivers(sender)
File "/home/webmaster/tc56/env/lib/python3.6/site-packages/django/dispatch/dispatcher.py", line 193, in <listcomp>
for receiver in self._live_receivers(sender)
File "/home/webmaster/tc56/env/lib/python3.6/site-packages/cms/signals/page.py", line 8, in pre_save_page
instance.clear_cache(menu=True)
File "/home/webmaster/tc56/env/lib/python3.6/site-packages/cms/models/pagemodel.py", line 963, in clear_cache
menu_pool.clear(site_id=self.node.site_id)
File "/home/webmaster/tc56/env/lib/python3.6/site-packages/django/db/models/fields/related_descriptors.py", line 184, in __get__
rel_obj = self.get_object(instance)
File "/home/webmaster/tc56/env/lib/python3.6/site-packages/django/db/models/fields/related_descriptors.py", line 159, in get_object
return qs.get(self.field.get_reverse_related_filter(instance))
File "/home/webmaster/tc56/env/lib/python3.6/site-packages/django/db/models/query.py", line 380, in get
self.model._meta.object_name
cms.models.pagemodel.DoesNotExist: Problem installing fixture '/home/webmaster/tc56/dump.json': TreeNode matching query does not exist.
This was fixed a few days ago.
Will land with django CMS 3.5.3

Migration urls in app ...has no Migration class

When I try to run migration I get "Migration urls in app *** has no Migration class"? I just added new app.
Have no idea what direction to look. Traceback:
C:\Users\PAPA\DEV\liberty\lib\site-packages\django\db\models\__init__.py:55:
RemovedInDjango19Warning: The utilities in django.db.models.loading are deprecated
in favor of the new application loading system.
from . import loading
Traceback (most recent call last): File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "...\django\core\management\__init__.py", line 338, in execute_from_command_line
utility.execute()
File "...\django\core\management\__init__.py", line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "...\django\core\management\base.py", line 390, in run_from_argv
self.execute(*args, **cmd_options)
File "...\django\core\management\base.py", line 441, in execute
output = self.handle(*args, **options)
File "...\django\core\management\commands\makemigrations.py", line 63, in handle
loader = MigrationLoader(None, ignore_no_migrations=True)
File "...\django\db\migrations\loader.py", line 47, in __init__
self.build_graph()
File "...\django\db\migrations\loader.py", line 174, in build_graph
self.load_disk()
File "...\django\db\migrations\loader.py", line 109, in load_disk
"Migration %s in app %s has no Migration class" % (migration_name, app_config.label)
django.db.migrations.loader.BadMigrationError: Migration urls in app expense has no
Migration class
That exception
BadMigrationError: "Migration *** in app *** has no Migration class"
is raised if the "migrations/" directory of the application contains a file that is not a valid migration file.
In your case it is a file "urls.py" in migrations of the application "expense".

Django Migration Error - NodeNotFoundError

Django verstion 1.8
Trying to migrate a newly added app in my project. Here is the traceback error:
Traceback (most recent call last):
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 354, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 346, 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 394, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 445, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/makemigrations.py", line 63, in handle
loader = MigrationLoader(None, ignore_no_migrations=True)
File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/loader.py", line 47, in __init__
self.build_graph()
File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/loader.py", line 318, in build_graph
_reraise_missing_dependency(migration, parent, e)
File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/loader.py", line 288, in _reraise_missing_dependency
raise exc
django.db.migrations.graph.NodeNotFoundError: Migration weather.0001_initial dependencies reference nonexistent parent node (u'machines', u'0006_auto_20150921_1327')
I have not found much helpful information in researching this. Syntax is correct in all models. Here is what doesn't make sense: this is just a copy of a working project. So it works on one computer, but not here. The machines model it's referencing has already been created and is working. Any ideas???
You are getting the error because the migration you are trying to run, weather.0001_initial, depends on a migration machines.0006_auto_20150921_1327 which does not exist.
If you can't find the missing migration file, you'll have to delete and recreate the migrations for the weather app, so that they don't depend on the missing migration.
You are getting this error because you are missing the
__init__.py
file in your migrations folder.
For me, it worked after adding this file.

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.