Modify

Ticket #606 (closed defect: invalid)

Opened 4 years ago

Last modified 3 years ago

The "convert_to_south" command fails if "models" is a package (directory)

Reported by: al.the.x@… Owned by: andrew
Priority: blocker Milestone: 0.7.3
Component: commands Version: 0.7.1
Keywords: conver_to_south models_in_package Cc:

Description

I've attempted this several different times to test it, but if the "models" module is a package - a directory containing an __init__.py file and others that are imported therein - the "convert_to_south" command fails upon trying to apply the migrations. I imagine that other South-supplied commands would also fail. Example:

  • project/
    • accounts/
      • models/
        • __init__.py
        • base.py
        • main.py
>>> ./project/manage.py convert_to_south accounts
Creating migrations directory at '.../project/accounts/migrations'...
Creating __init__.py in '.../project/accounts/migrations'...
 + Added model accounts.Client
 + Added model accounts.Caregiver
 + Added model accounts.Address
 + Added model accounts.PhoneNumber
 + Added model accounts.UserProfile
 + Added model accounts.Unavailability
Created 0001_initial.py. You can now apply this migration with: ./manage.py migrate accounts
 - Soft matched migration 0001 to 0001_initial.
Running migrations for accounts:
- Nothing to migrate.
 - Loading initial data for accounts.
No fixtures found.
None
Traceback (most recent call last):
  File "./project/manage.py", line 11, in <module>
    execute_manager(settings)
  File "/.../django/core/management/__init__.py", line 438, in execute_manager
    utility.execute()
  File "/.../django/core/management/__init__.py", line 379, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/.../django/core/management/base.py", line 191, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/.../django/core/management/base.py", line 218, in execute
    output = self.handle(*args, **options)
  File "/.../south/management/commands/convert_to_south.py", line 74, in handle
    management.call_command("migrate", app, "0001", fake=True, verbosity=verbosity)
  File "/.../django/core/management/__init__.py", line 166, in call_command
    return klass.execute(*args, **defaults)
  File "/.../django/core/management/base.py", line 218, in execute
    output = self.handle(*args, **options)
  File "/.../south/management/commands/migrate.py", line 109, in handle
    ignore_ghosts = ignore_ghosts,
  File "/.../south/migration/__init__.py", line 215, in migrate_app
    post_migrate.send(None, app=app_label)
  File "/.../django/dispatch/dispatcher.py", line 162, in send
    response = receiver(signal=self, sender=sender, **named)
  File "/.../south/signals.py", line 22, in create_permissions_compat
    create_permissions(get_app(app), (), 0)
  File "/.../django/contrib/auth/management/__init__.py", line 25, in create_permissions
    ctype = ContentType.objects.get_for_model(klass)
  File "/.../django/contrib/contenttypes/models.py", line 40, in get_for_model
    self._add_to_cache(self.db, ct)
  File "/.../django/contrib/contenttypes/models.py", line 71, in _add_to_cache
    key = (model._meta.app_label, model._meta.object_name.lower())
AttributeError: 'NoneType' object has no attribute '_meta'

While its a component of "django.contrib.contenttypes" that's complaining, I don't get the same error when running "syncdb" without South installed. The content types are correctly installed by "syncdb", even after I "reset" them (and South). All my apps currently organize models into Python packages, but I was able to create a fresh application that didn't, sync it, and convert it to South successfully.

Attachments

Change History

comment:1 Changed 4 years ago by andrew

  • Status changed from new to infoneeded
  • Milestone set to 0.7.3

This worked fine for me locally; can you give me a bit more information about how the models are laid out (the source to the models or a minimal example that causes the same error would be good)?

Also, can you try it on the latest development version (info on how to install it is in the docs, but it's basically pip install South==dev or easy_install South==dev? We've done a few fixes since 0.7.1.

comment:2 Changed 3 years ago by jag@…

  • Status changed from infoneeded to assigned

I've got something similar.

myapp

/models

/init.py
/master.py
/auxiliary.py

init.py contains:

from myapp.models.master import *
from myapp.models.auxiliary import *

Both master.py and auxiliary.py have all properties explicitly listing what is to be exported. However the initial migration for myapp is empty, and another app referring to models in myapp has the referenced app called 'models', e.g.:

db.create_table('otherapp_foomodel',
# ... snip ...
('member', self.gf('django.db.models.fields.related.OneToOneField?')(to=ormmodels.Member?, unique=True)),

... where Member is a model in myapp.

Does that help?

comment:3 Changed 3 years ago by andrew

  • Status changed from assigned to infoneeded

Hm, no, that's what I have, and it works fine. What version are you using? As I said, I tested using the latest development version.

comment:4 Changed 3 years ago by andrew

  • Status changed from infoneeded to closed
  • Resolution set to invalid

Closing due to inactivity.

View

Add a comment

Modify Ticket

Action
as closed
The resolution will be deleted. Next status will be 'reopened'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.