django使用python manage.py makemigrations命令不能生成数据库表

snowfox008 发布于 2018/04/11 22:00
阅读 5K+
收藏 0


G:\pythondemo\myblog>python manage.py makemigrations
Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\django\core\managem
ent\__init__.py", line 367, in execute_from_command_line
    utility.execute()
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\django\core\managem
ent\__init__.py", line 341, in execute
    django.setup()
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\django\__init__.py"
, line 27, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\django\apps\registr
y.py", line 108, in populate
    app_config.import_models(all_models)
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\django\apps\config.
py", line 199, in import_models
    self.models_module = import_module(models_module_name)
  File "C:\Program Files (x86)\Python36-32\lib\importlib\__init__.py", line 126,
 in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "G:\pythondemo\myblog\blog\models.py", line 7, in <module>
    class Article(models.Model):
  File "G:\pythondemo\myblog\blog\models.py", line 8, in Article
    title = models.CharField(max_lenth=32,default='True')
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\django\db\models\fi
elds\__init__.py", line 1043, in __init__
    super(CharField, self).__init__(*args, **kwargs)
TypeError: __init__() got an unexpected keyword argument 'max_lenth'

G:\pythondemo\myblog>
G:\pythondemo\myblog>
G:\pythondemo\myblog>dir
 驱动器 G 中的卷是 新加卷
 卷的序列号是 CC4F-88E9

 G:\pythondemo\myblog 的目录

2018/04/11  21:20    <DIR>          .
2018/04/11  21:20    <DIR>          ..
2018/04/11  21:24    <DIR>          .idea
2018/04/11  21:11    <DIR>          blog
2018/04/11  14:56            12,288 db.sqlite3
2018/04/11  21:20               804 manage.py
2018/04/11  17:01    <DIR>          myblog
               2 个文件         13,092 字节
               5 个目录 34,452,447,232 可用字节

G:\pythondemo\myblog>
G:\pythondemo\myblog>
G:\pythondemo\myblog>
G:\pythondemo\myblog>python manage.py makemigrations
Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\django\core\managem
ent\__init__.py", line 367, in execute_from_command_line
    utility.execute()
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\django\core\managem
ent\__init__.py", line 341, in execute
    django.setup()
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\django\__init__.py"
, line 27, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\django\apps\registr
y.py", line 108, in populate
    app_config.import_models(all_models)
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\django\apps\config.
py", line 199, in import_models
    self.models_module = import_module(models_module_name)
  File "C:\Program Files (x86)\Python36-32\lib\importlib\__init__.py", line 126,
 in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "G:\pythondemo\myblog\blog\models.py", line 7, in <module>
    class Article(models.Model):
  File "G:\pythondemo\myblog\blog\models.py", line 8, in Article
    title = models.CharField(max_lenth=32,default='True')
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\django\db\models\fi
elds\__init__.py", line 1043, in __init__
    super(CharField, self).__init__(*args, **kwargs)
TypeError: __init__() got an unexpected keyword argument 'max_lenth'

G:\pythondemo\myblog>
G:\pythondemo\myblog>
G:\pythondemo\myblog>
G:\pythondemo\myblog>

加载中
0
tsingliu
tsingliu
migrate才是生成表
0
LuckyWiky
LuckyWiky
不是写得很清楚吗? models.py line 8 max_lenth => max_length
0
snowfox008
snowfox008

models.py line 8 max_lenth  这个参数好像不存在一样;下面是我在models.py里面写的代码

from __future__ import unicode_literals

from django.db import models

class Article(models.Model):
    title = models.CharField(max_lenth=16,default='True')
    content = models.TextField(null= True)
0
铂金胖子
铂金胖子

max_length 写错了

0
snowfox008
snowfox008

多谢!道友指点!终于成功了。

膜拜大神!!!

返回顶部
顶部