简体   繁体   English

ArrayField缺少1个必需的位置参数

[英]ArrayField missing 1 required positional argument

I have imported the following header file 我导入了以下头文件

from django.contrib.postgres.fields import ArrayField

Used the following in the model 在模型中使用以下内容

question_array = ArrayField(models.IntegerField, blank=True,)

i get the following error 我收到以下错误

Traceback (most recent call last)
  File "C:\Program Files (x86)\Python\Python35-32\lib\site-packages\django-1.10.4-py3.5.egg\django\__init__.py", line 27, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "C:\Program Files (x86)\Python\Python35-32\lib\site-packages\django-1.10.4-py3.5.egg\django\apps\registry.py", line 108, in populate
    app_config.import_models(all_models)
  File "C:\Program Files (x86)\Python\Python35-32\lib\site-packages\django-1.10.4-py3.5.egg\django\apps\config.py", line 199, in import_models
    self.models_module = import_module(models_module_name)
  File "C:\Program Files (x86)\Python\Python35-32\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 665, in exec_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "C:\Users\DELL\Desktop\cstrom\comp\models.py", line 24, in <module>
    class User(models.Model):
  File "C:\Program Files (x86)\Python\Python35-32\lib\site-packages\django-1.10.4-py3.5.egg\django\db\models\base.py", line 157, in __new__
    new_class.add_to_class(obj_name, obj)
  File "C:\Program Files (x86)\Python\Python35-32\lib\site-packages\django-1.10.4-py3.5.egg\django\db\models\base.py", line 316, in add_to_class
    value.contribute_to_class(cls, name)
  File "C:\Program Files (x86)\Python\Python35-32\lib\site-packages\django-1.10.4-py3.5.egg\django\db\models\fields\__init__.py", line 689, in contribute_to_class
    self.set_attributes_from_name(name)
  File "C:\Program Files (x86)\Python\Python35-32\lib\site-packages\django-1.10.4-py3.5.egg\django\contrib\postgres\fields\array.py", line 75, in set_attributes_from_name
    self.base_field.set_attributes_from_name(name)
TypeError: set_attributes_from_name() missing 1 required positional argument: 'name'

As per the docs 按照文档

You still need to fully define the field inside the array field 您仍然需要在数组字段内完全定义字段

question_array = ArrayField(models.IntegerField(null=True, blank=True), blank=True,)

models.IntegerField is a function not a property, so you will be required to call it like a function. models.IntegerField是一个函数而不是属性,因此您需要像函数一样调用它。 () at the end ()最后

question_array = ArrayField(models.IntegerField(blank=True), blank=True,)

Read more about it here . 在这里阅读更多相关信息。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM