我在我的www.example.com中定义了这个模型models.py:
class FarmAnalytics(models.Model):
water_saved = models.FloatField(default=0, decimal_places=2)
last_full_execution = models.DateField(auto_now=False, auto_now_add=False)
current_state = models.CharField(max_length=50) #watering/calculating/resting
而且,我得到了下面的错误:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 312, in execute
django.setup()
File "/Library/Python/2.7/site-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Library/Python/2.7/site-packages/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File "/Library/Python/2.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/krishna/Documents/temp/tutorial/quickstart/models.py", line 10, in <module>
class FarmAnalytics(models.Model):
File "/Users/krishna/Documents/temp/tutorial/quickstart/models.py", line 11, in FarmAnalytics
water_saved = models.FloatField(default = 0, decimal_places = 2)
TypeError: __init__() got an unexpected keyword argument 'decimal_places'
我不知道我做错了什么,我对django还是个新手,今天才开始使用它。
2条答案
按热度按时间aij0ehis1#
字段类型
FloatField
不接受decimal_places
作为选项,它是DecimalField
的选项。如果需要,您可以尝试将FloatField更改为DecimalField。iovurdzv2#
我得到了类似的错误如下:
TypeError:init()获得意外的关键字参数"max_digits"
因为我将
max_digits=5
设置为大整数字段()、整数字段()、小整数字段()、正大整数字段()、正整数字段()和正小整数字段(),如下所示:因此,我用DecimalField替换它们,如下所示,然后上面的错误就解决了: