这是myles.py中的代码
from django.db import models
from django.utils import timezone
class Book(models.Model):
title = models.CharField(max_length = 200)
author = models.CharField(max_lenght = 200)
description = models.TextField()
publish_date = models.DateField(Default= timezone.now)
当我输入./manage.py makemigrations执行错误时 这就是我所看到的嘘 仍然错误没有控制空间知道什么时候我指向鼠标到django它出现未解决的参考'django'虽然我安装它pip安装django == 1.8我每次运行sudo pip安装--ignore-installed virtualenvwrapper因为当我使用workon bookstore-django它直到我运行sudo pip install才会执行--ignore-installed virtualenvwrapper我在这个领域太初学了
(bookstore-django) bavlys-Mac:bookstore bavlymorcos$ ./manage.py makemigrations store
Traceback (most recent call last):
File "./manage.py", line 11, in <module>
execute_from_command_line(sys.argv)
File "/Users/bavlymorcos/.virtualenvs/bookstore-django/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/Users/bavlymorcos/.virtualenvs/bookstore-django/lib/python2.7/site-packages/django/core/management/__init__.py", line 312, in execute
django.setup()
File "/Users/bavlymorcos/.virtualenvs/bookstore-django/lib/python2.7/site-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Users/bavlymorcos/.virtualenvs/bookstore-django/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File "/Users/bavlymorcos/.virtualenvs/bookstore-django/lib/python2.7/site-packages/django/apps/config.py", line 198, in import_models
self.models_module = import_module(models_module_name)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/Users/bavlymorcos/Desktop/development/bookstore/store/models.py", line 6, in <module>
class Book(models.Model):
File "/Users/bavlymorcos/Desktop/development/bookstore/store/models.py", line 10, in Book
publish_date = models.DateField(Default=timezone.now)
File "/Users/bavlymorcos/.virtualenvs/bookstore-django/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 1201, in __init__
super(DateField, self).__init__(verbose_name, name, **kwargs)
TypeError: __init__() got an unexpected keyword argument 'Default'
答案 0 :(得分:3)
Charfield
部分应为CharField
。
在/Users/bavlymorcos/Desktop/development/bookstore/store/models.py中,行号。 6,
应该是
title = models.CharField(max_length = 200)
即。 F in field应该是Capital。 (CharField而不是Charfield)
答案 1 :(得分:0)
我解决了问题谢谢你们
问题出在model.py中我将其更改为
from django.db import models
from django.utils import timezone
class Book(models.Model):
title = models.CharField(max_length=200)
author = models.CharField(max_length=200)
description = models.TextField()
publish_date = models.DateField(default=timezone.now)