环境python3,dango1.11.7,IDE: pycharm

Django在模型数据迁移的时候报错:'%s' must supply a name attribute." % entry)

错误类型为:AttributeError: type object 'AppConfig' has no attribute 'name'

racking file by folder pattern:  migrations
Traceback (most recent call last):
  File "C:\Users\yww\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\apps\config.py", line 140, in create
    app_name = cls.name
AttributeError: type object 'AppConfig' has no attribute 'name'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "S:\PyCharm 2018.1.4\helpers\pycharm\django_manage.py", line 52, in <module>
    run_command()
  File "S:\PyCharm 2018.1.4\helpers\pycharm\django_manage.py", line 46, in run_command
    run_module(manage_file, None, '__main__', True)
  File "C:\Users\yww\AppData\Local\Programs\Python\Python36-32\lib\runpy.py", line 205, in run_module
    return _run_module_code(code, init_globals, run_name, mod_spec)
  File "C:\Users\yww\AppData\Local\Programs\Python\Python36-32\lib\runpy.py", line 96, in _run_module_code
    mod_name, mod_spec, pkg_name, script_name)
  File "C:\Users\yww\AppData\Local\Programs\Python\Python36-32\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "F:/python_2/MxShop\manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "C:\Users\yww\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\management\__init__.py", line 364, in execute_from_command_line
    utility.execute()
  File "C:\Users\yww\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\management\__init__.py", line 338, in execute
    django.setup()
  File "C:\Users\yww\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\__init__.py", line 27, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "C:\Users\yww\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\apps\registry.py", line 85, in populate
    app_config = AppConfig.create(entry)
  File "C:\Users\yww\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\apps\config.py", line 143, in create
    "'%s' must supply a name attribute." % entry)
django.core.exceptions.ImproperlyConfigured: 'trade.apps.AppConfig' must supply a name attribute.
Process finished with exit code 1

百度了好久都没有。只能自己找。

最后发现是在seeting里面进行app注册时出错,

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'users.apps.UsersConfig',
    'DjangoUeditor',
    'goods.apps.GoodsConfig',
    #这是错误的,由于是点回车,太快,导致的
    #trade.apps.AppConfig
    'trade.apps.TradeConfig',
    'user_operation.apps.UserOperationConfig',

改回来就OK了。

关于AttributeError: type object ‘XXXXXX’ has no attribute 'name’的报错的原因,先运行运行一段代码 class Person(object): def __init__(self,name): self.name=name def play(self): print('工作') if __name__ == '__main__': p=Person('KB') p.play 这两天在学习python的时候,会搞一些测试代码,有时候控制台就会有“AttributeError: 'function' object has no attribute 'name'”的报错,编译器也没报错 0. 概述: settings.py文件中的INSTALLED_APPS中添加自定义子应用时,需要将子应用所在目录加入导报路径sys.path(如果子应用本身就在项目根路径下就不需要)。要么就要设置子应用的配置类的name值带上导包路径。 1. 相关报错django.core.exceptions.ImproperlyConfigured: Cannot import ‘users’. Check that ‘meiduo_project.apps.users.apps.UsersConfig.nam 在项目(blogsite)注册应用(blog)时提示错误信息:[blog.apps.AppConfig]must supply a name attribute 错误写法: INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 在做《Machine Learning in Action》书中的第三章绘制树形图时遇到了这个问题AttributeError: type object 'str' has no attribute '_name_' 很明显是if type(secondDict[key])._name_  == ‘dict’:这一句有问题,在python3中并没有type(secondDict[key])._n 查阅大部分资料,大部分说 Python 的问题。这个项目前端使用 React, 后端使用 Python 的 djongo 框架。 询问后端的同事,主要的原因是前端传递的参数的数据类型不正确。后端需要一个 string 的 “tr... File "C:\Python36-32\lib\importlib\__init__.py", line 166, in reload _bootstrap._exec(spec, module) File "&lt;frozen importlib._bootstrap&gt;", l...