﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
25292	"""'str' object has no attribute '_meta'"" crash in ManyToManyField.through_fields check"	thbarrons	nobody	"'''version 1.8 doesn't handle an error properly in ManyToManyField.through_fields and gives useless feedback when performing system checks'''

I made a typo in defining a many to many through field in a model.  See below.  In my ManyToManyField.through_field for ""Stage"" I have ""StageCatgeory"" which is not correct the e and g are backwards.

See the stack trace below when running in v 1.8.4. it provides this useless info... '''AttributeError: 'str' object has no attribute '_meta'.'''

It wasn't until I tried running my app in 1.7.10, stack trace also below, that I got useful feedback on the problem and was able to solve it.   '''Field specifies a many-to-many relation through model 'StageCatgeory', which has not been installed.'''

This seems like a bug that 1.7 handled it and 1.8 did not.



{{{
class Stage(models.Model):
    stage_id = models.AutoField(primary_key=True)
    categories = models.ManyToManyField('Category', through='StageCatgeory', related_name=""stage_category"")

class StageCategory(models.Model):
    stage = models.ForeignKey('Stage', db_column='stage_id')
    category = models.ForeignKey('Category',  db_column='category_id')

class Category(models.Model):
    category_id = models.AutoField(primary_key=True)
    stage = models.ManyToManyField('Stage', through='StageCategory', related_name=""stage_category"")
}}}




{{{
Django version 1.8.4, using settings 'my.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
Performing system checks...

Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x102cbad90>
Traceback (most recent call last):
  File ""/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/django/utils/autoreload.py"", line 225, in wrapper
    fn(*args, **kwargs)
  File ""/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/django/core/management/commands/runserver.py"", line 110, in inner_run
    self.validate(display_num_errors=True)
  File ""/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/django/core/management/base.py"", line 468, in validate
    return self.check(app_configs=app_configs, display_num_errors=display_num_errors)
  File ""/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/django/core/management/base.py"", line 481, in check
    include_deployment_checks=include_deployment_checks,
  File ""/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/django/core/checks/registry.py"", line 72, in run_checks
    new_errors = check(app_configs=app_configs)
  File ""/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/django/core/checks/model_checks.py"", line 28, in check_all_models
    errors.extend(model.check(**kwargs))
  File ""/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/django/db/models/base.py"", line 1207, in check
    errors.extend(cls._check_long_column_names())
  File ""/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/django/db/models/base.py"", line 1648, in _check_long_column_names
    for m2m in f.rel.through._meta.local_fields:
AttributeError: 'str' object has no attribute '_meta'
}}}




{{{
Django version 1.7.10, using settings 'my.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
Performing system checks...

Unhandled exception in thread started by <function wrapper at 0x103de3cf8>
Traceback (most recent call last):
  File ""/Users/me/virtualEnvs/myV2.7/lib/python2.7/site-packages/django/utils/autoreload.py"", line 222, in wrapper
    fn(*args, **kwargs)
  File ""/Users/me/virtualEnvs/myV2.7/lib/python2.7/site-packages/django/core/management/commands/runserver.py"", line 105, in inner_run
    self.validate(display_num_errors=True)
  File ""/Users/me/virtualEnvs/myV2.7/lib/python2.7/site-packages/django/core/management/base.py"", line 362, in validate
    return self.check(app_configs=app_configs, display_num_errors=display_num_errors)
  File ""/Users/me/virtualEnvs/myV2.7/lib/python2.7/site-packages/django/core/management/base.py"", line 414, in check
    raise CommandError(msg)
django.core.management.base.CommandError: System check identified some issues:

ERRORS:
main.Stage.categories: (fields.E331) Field specifies a many-to-many relation through model 'StageCatgeory', which has not been installed.

System check identified 1 issue (0 silenced).
}}}"	Bug	closed	Core (System checks)	1.8	Normal	fixed			Accepted	0	0	0	0	1	0
