Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Error when calling the metaclass bases #22

Closed
fbngrm opened this issue May 5, 2014 · 3 comments
Closed

TypeError: Error when calling the metaclass bases #22

fbngrm opened this issue May 5, 2014 · 3 comments

Comments

@fbngrm
Copy link

fbngrm commented May 5, 2014

Using South for migrations I get a TypeError when initializing:

./manage.py schemamigration myapp --initial

TypeError: Error when calling the metaclass bases
type() argument 1 must be string, not unicode

class Photo(models.Model):
    name = models.CharField(max_length=50)
    image = models.ImageField(upload_to='...')

class Gallery(models.Model):
    name = models.CharField(max_length=50)
    photos = SortedManyToManyField(Photo)
@gregmuellegger
Copy link
Collaborator

Ok. I will have a look. But before that, could you please re-run the
command with the --traceback option and paste the full resulting
traceback here?

./manage.py schemamigration myapp --initial --traceback

That would make the investigation much easier.
Am 05.05.2014 22:08 schrieb "fgrimme" notifications@github.com:

Using South for migrations I get a TypeError when initializing:

./manage.py schemamigration myapp --initial

TypeError: Error when calling the metaclass bases
type() argument 1 must be string, not unicode

class Photo(models.Model):
name = models.CharField(max_length=50)
image = models.ImageField(upload_to='...')

class Gallery(models.Model):
name = models.CharField(max_length=50)
photos = SortedManyToManyField(Photo)


Reply to this email directly or view it on GitHubhttps://github.com//issues/22
.

@fbngrm
Copy link
Author

fbngrm commented May 6, 2014

Thx - here is the traceback.
For some reason model_name is unicode instead of str here. May be this is related to Python 3 support?
https://code.djangoproject.com/ticket/20207#no1

Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 222, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 254, in execute
    self.validate()
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 280, in validate
    num_errors = get_validation_errors(s, app)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/validation.py", line 35, in get_validation_errors
    for (app_name, error) in get_app_errors().items():
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/loading.py", line 166, in get_app_errors
    self._populate()
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/loading.py", line 72, in _populate
    self.load_app(app_name, True)
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/loading.py", line 96, in load_app
    models = import_module('.models', app_name)
  File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py", line 35, in import_module
    __import__(name)
  File "/home/f/work/py/vojd-website/vojdnet/models.py", line 110, in <module>
    class Gallery(models.Model):
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/base.py", line 145, in __new__
    new_class.add_to_class(obj_name, obj)
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/base.py", line 265, in add_to_class
    value.contribute_to_class(cls, name)
  File "/usr/local/lib/python2.7/dist-packages/django_sortedm2m-0.2.0-py2.7.egg/sortedm2m/fields.py", line 165, in contribute_to_class
    self.rel.through = self.create_intermediary_model(cls, name)
  File "/usr/local/lib/python2.7/dist-packages/django_sortedm2m-0.2.0-py2.7.egg/sortedm2m/fields.py", line 159, in create_intermediary_model
    model = type(model_name, (models.Model,), attrs)
TypeError: Error when calling the metaclass bases
    type() argument 1 must be string, not unicode

I fixed it changing the line:
model = type(model_name, (models.Model,), attrs)
to
model = type(str(model_name), (models.Model,), attrs)

This raises another error related to south:

! Cannot freeze field 'vojdnet.gallery.photos'
 ! (this field has class sortedm2m.fields.SortedManyToManyField)

 ! South cannot introspect some fields; this is probably because they are custom
 ! fields. If they worked in 0.6 or below, this is because we have removed the
 ! models parser (it often broke things).
 ! To fix this, read http://south.aeracode.org/wiki/MyFieldsDontWork

I am using South 0.7.6, Django 1.5.1 and Python 2.7

@fbngrm
Copy link
Author

fbngrm commented May 6, 2014

I was able to resolve the unicode & introspection rules errors by installing everything again via pip.
I used python setup.py install before which resulted in missing introspection rules for the sortedm2m field.

Thanks for your effort anyway.

@fbngrm fbngrm closed this as completed May 6, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants