首页 文章

在Django中获取已知错误在模型中

提问于
浏览
1

Model.py

from django.db import models
 class Albums(models.Model):
     artist = models.CharField(max_lenght=250)
     Albums_Name = models.CharField(max_lenght = 500)
     Album_logo = models.CharField(max_lenght = 250)
 class Songs(models.Model):
     albums=models.ForeignKey(Albums,on_delete=models.CASCADE)
     file_type = models.CharField(max_lenght = 500)
     Song_title = models.CharField(max_lenght = 500)

setting.py

INSTALLED_APPS = [
    'Ganaana.apps.GanaanaConfig',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles', ]

错误:命令使用:python manage.py makemigrations Ganaana Traceback(最近一次调用最后一次):文件"manage.py",第22行,在execute_from_command_line(sys.argv)文件“C:\ Program Files \ Python36 \ lib \ site-packages \ django- 1.11.5-
py3.6.egg \ django \ core \ management__init __ . py ", line 364, in execut e_from_command_line utility.execute() File " C:\ Program Files \ Python36 \ lib \ site-packages \ django-1.11.5-py3.6.egg \ django \ core \ management__init __ . py ", line 338, in execute django.setup() File " C: \ Program Files \ Python36 \ lib \ site-packages \ django-1.11.5- py3.6.egg \ django__init __ . py ", line 27, in setup apps.populate(settings.INSTALLED_APPS) File " C:\ Program Files \ Python36 \ lib \ site-packages \ django-1.11.5 py3.6 .egg \ django \ apps \ registry.py ", line 108, in populate app_config.import_models() File " C:\ Program Files \ Python36 \ lib \ site-packages \ django-1.11.5- py3.6.egg \ django \ apps \ config.py ", line 202, in import_models self.models_module = import_module(models_module_name) File " C:\ Program Files \ Python36 \ lib \ importlib__init __ . py ", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File " ", line 978, in _gcd_import File " ", line 961, in _find_and_load File " ", line 950, in _find_and_load_unlocked File " ", line 655, in _load_unlocked File " ", line 678, in exec_module File " ", line 205, in _call_with_frames_removed File " E:\ PythonDjango \ website \ Ganaana \ models.py ", line 4, in class Albums(models.Model): File " E:\ PythonDjango \ website \ Ganaana \ models.py ", line 5, in Albums artist = models.CharField(self,max_lenght = 250) NameError: name 'self' is not defined PS E:\PythonDjango\website> python manage.py makemigration Ganaana Traceback (most recent call last): File " manage.py ", line 22, in execute_from_command_line(sys.argv) File " C:\ Program Files \ Python36 \ LIB \站点包\ Django的1.11.5-
py3.6.egg \ django \ core \ management__init __ . py ", line 364, in execut e_from_command_line utility.execute() File " C:\ Program Files \ Python36 \ lib \ site-packages \ django-1.11.5-py3.6.egg \ django \ core \ management__init __ . py ", line 338, in execute django.setup() File " C: \ Program Files \ Python36 \ lib \ site-packages \ django-1.11.5-py3.6.egg \ django__init __ . py ", line 27, in setup apps.populate(settings.INSTALLED_APPS) File " C:\ Program Files \ Python36 \ lib \ site-packages \ django-1.11.5- py3 . 6.egg \ django \ apps \ registry.py ", line 108, in populate app_config.import_models() File " C:\ Program Files \ Python36 \ lib \ site-packages \ django-1.11.5- py3.6.egg \ django \ apps \ config.py ", line 202, in import_models self.models_module = import_module(models_module_name) File " C:\ Program Files \ Python36 \ lib \ importlib__init __ . py ", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File " ", line 978, in _gcd_import File " ", line 961, in _find_and_load File " ", line 950, in _find_and_load_unlocked PS E:\PythonDjango\website> python manage.py makemigration Ganaana Traceback (most recent call last): File " manage.py ", line 22, in execute_from_command_line(sys.argv) File " C:\ Program Files \ Python36 \ lib \ site-packages \ django-1.11.5-py3.6.egg \ django \ core \ management__init __ . py ", line 364, in execut e_from_command_line utility.execute() File " C:\ Program Files \ Python36 \ lib \ site-packages \ django-1.11.5-
py3.6.egg \ django \ core \ management__init __ . py ", line 338, in execute django.setup() File " C:\ Program Files \ Python36 \ lib \ site-packages \ django-1.11.5-py3.6.egg \ django__init __ . py ", line 27, in setup apps.populate(settings.INSTALLED_APPS) File " C:\ Program Files \ Python36 \ lib \ site-packages \ django-1.11.5- py3.6.egg \ django \ apps \ registry.py ", line 108, in populate app_config.import_models() File " C:\ Program Files \ Python36 \ lib \ site-packages \ django-1.11.5- py3 . 6.egg \ django \ apps \ config.py ", line 202, in import_models self.models_module = import_module(models_module_name) File " C:\ Program Files \ Python36 \ lib \ importlib__init __ . py ", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File " ", line 978, in _gcd_import File " ", line 961, in _find_and_load File " ", line 950, in _find_and_load_unlocked File " ", line 655, in _load_unlocked File " ", line 678, in exec_module File " ", line 205, in _call_with_frames_removed File " E:\ PythonDjango \ website \ Ganaana \ models.py ", line 4, in class Albums(models.Model): File " E:\ PythonDjango \ website \ Ganaana \ models.py ", line 5, in Albums artist = models.CharField(max_lenght=250) File " C:\ Program Files \ Python36 \ lib \ site-packages \ django-1.11.5- py3.6.egg \ django \ db \ models \ fields__init __ . py“,line 1061,in init super(CharField,self). init (* args,** kwargs)TypeError: init ()得到了一个意外的关键字参数'max_lenght'我不明白我的错误?我给了一个正确的名称仍然收到错误?有人能识别错误

1 回答

  • 2

    这应该是 max_length 而不是 max_lenght . 小错字 - 请在您的模型中更改它,看看它是否解决了问题:)

相关问题