简体   繁体   English

当我运行 migrate 命令时。 AttributeError: 'Model' 对象没有属性 '_meta'

[英]When i run migrate command. AttributeError: 'Model' object has no attribute '_meta'

When i run the following command python manage.py makemigrations I am using Django version 3.0.3 and python 3.8 I am learning django from documentation but it could not run makemigrations comman当我运行以下命令 python manage.py makemigrations 我使用的是 Django 3.0.3 和 python 3.8 我正在从文档中学习 django 但它无法运行 makemigrations comman

python manage.py makemigrations polls
Traceback (most recent call last):
  File "manage.py", line 21, in <module>
    main()
  File "manage.py", line 17, in main
    execute_from_command_line(sys.argv)
  File "C:\Program Files (x86)\Python38-32\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "C:\Program Files (x86)\Python38-32\lib\site-packages\django\core\management\__init__.py", line 377, in execute
    django.setup()
  File "C:\Program Files (x86)\Python38-32\lib\site-packages\django\__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "C:\Program Files (x86)\Python38-32\lib\site-packages\django\apps\registry.py", line 114, in populate
    app_config.import_models()
  File "C:\Program Files (x86)\Python38-32\lib\site-packages\django\apps\config.py", line 211, in import_models
    self.models_module = import_module(models_module_name)
  File "C:\Program Files (x86)\Python38-32\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load        
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked        
  File "<frozen importlib._bootstrap_external>", line 783, in exec_module  
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "C:\Users\sergio\Documents\Django-Project\2. AdvanceView\mysite\polls\models.py", line 8, in <module>
    class Question(models.Model):
  File "C:\Users\sergio\Documents\Django-Project\2. AdvanceView\mysite\polls\models.py", line 9, in Question
    question_text = models.Model(max_length=200)
  File "C:\Program Files (x86)\Python38-32\lib\site-packages\django\db\models\base.py", line 408, in __init__
    opts = self._meta
AttributeError: 'Model' object has no attribute '_meta'


Your question_text should probably be a CharField , not a Model object:您的question_text应该是CharField ,而不是Model对象:

class Question(models.Model):
    # CharField instead of Model ↓
    question_text = models.CharField(max_length=200)
    # ⋮

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Django AttributeError:“模型”对象没有属性“ _meta” - Django AttributeError: 'Model' object has no attribute '_meta' Django migrate AttributeError: 'str' object 没有属性 '_meta' - Django migrate AttributeError: 'str' object has no attribute '_meta' model_to_dict: AttributeError: 'str' object 没有属性 '_meta' - model_to_dict: AttributeError: 'str' object has no attribute '_meta' Django - (Tagulous) AttributeError: type object 'Model' has no attribute '_meta' - Django - (Tagulous) AttributeError: type object 'Model' has no attribute '_meta' 使用加密的 SearchField 作为自定义用户 model (Django) 的密钥时出错:AttributeError: 'NoneType' object 没有属性 '_meta' - Error when using encrypted SearchField as key for custom user model (Django): AttributeError: 'NoneType' object has no attribute '_meta' AttributeError: &#39;tuple&#39; 对象在开始迁移时没有属性 &#39;startswith&#39; - AttributeError: 'tuple' object has no attribute 'startswith' when start migrate 我运行时 Flask 出现属性错误(AttributeError: 'NoneType' object has no attribute 'run' ) - attribute error in Flask when I run (AttributeError: 'NoneType' object has no attribute 'run' ) 如果 model._meta.abstract:AttributeError:类型 object 'ProductObject' 没有属性 '_meta' - if model._meta.abstract: AttributeError: type object 'ProductObject' has no attribute '_meta' AttributeError:类型对象“ Product”没有属性“ _meta” - AttributeError: type object 'Product' has no attribute '_meta' /&#39;tuple&#39;对象的AttributeError没有属性&#39;_meta&#39; - AttributeError at / 'tuple' object has no attribute '_meta'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM