Having TypeError: 'CharField' object is not callable after migrating with django
Having TypeError: 'CharField' object is not callable after migrating with django
这是我的 models.py 来自我的应用程序,django 版本是 4.0.4,我的 python 版本是 3.10.4。我制作了所有模型,并在制作 makemigrations 以生成数据库后给出了错误代码。
from enum import unique
from django.db import models
from django.utils import timezone
from django.core.validators import MinValueValidator, MaxValueValidator
# Create your models here.
class I_Articulos(models.Model):
pais = models.CharField('Pais', max_length=30, null=False, blank=False)
grupo_economico = models.CharField('Grupo_Economico', max_length=30, null=False, blank=False)
empresa = models.CharField('Empresa', max_length=30, null=False, blank=False)
sucursal = models.CharField('Sucursal', max_length=30, null=False, blank=False)
almacenado = models.CharField('Almacenado', max_length=30, null=False, blank=False)
id_rubro = models.FloatField('id_rubro', null=False, blank=False, default=0, validators=[MinValueValidator(0), MaxValueValidator(99999)], unique=True)
descuento_maximo = models.CharField = models.CharField('Descuento_Maximo', max_length=20, null=False, blank=False)
descuento_directo = models.CharField('Descuento_Directo', max_length=20, null=False, blank=False)
unidad_minima_venta = models.DecimalField('Unidad_Minima_Venta', max_digits=15, decimal_places=4, null=False, blank=False)
cantidad_unidades_unidad_venta = models.DecimalField('Cant_U_UV', max_length=30, null=False, blank=False)
unidad_venta = models.CharField('Unidad_Venta', max_length=30, null=False, blank=False)
descripcion_articulo = models.CharField('Descripcion_Articulo', max_length=100, null=False, blank=False)
codigo_articulo = models.CharField('Codigo_articulo', max_length=30, null=False, blank=False)
codigo_busqueda = models.CharField('Codigo_busqueda', max_length=30, null=False, blank=False)
id_divisiona = models.CharField('id_divisiona', max_length=20, null=False, blank=False)
id_segmento = models.CharField('id_segmento', max_length=20, null=False, blank=False)
id_subrublo = models.CharField('id_subrublo', max_length=20, null=False, blank=False)
id_linea = models.CharField('Pais', max_length=20, null=False, blank=False)
tipo_item = models.PositiveIntegerField('tipo_item', null=False, blank=False, default=0, validators=[MinValueValidator(0), MaxValueValidator(99999)])
combo_calcula_stock = models.CharField('combo_calcula_stock', max_length=30, null=False, blank=False)
vc_fechahora_ultima_modificacion = models.DateTimeField('vc_fechahora_ultima_modificacion', null=False, blank=False)
status = models.PositiveIntegerField('Status', null=False, blank=False, default=0, validators=[MinValueValidator(0), MaxValueValidator(99999)])
activo = models.CharField('Activo', max_length=1, null=False, blank=False)
fechahora_ultima_modificacion = models.DateTimeField('Pais', null=False, blank=False)
然后我 运行 python3 manage.py makemigrations 来生成我的数据库,但是给我这个错误:
(VENV) byakenda@byakenda-G5-5587:~/Documents/somewhere/trucksys$ python3 manage.py makemigrations
Traceback (most recent call last):
File "/home/somewhere/trucksys/manage.py", line 22, in <module>
main()
File "/home/somewhere/trucksys/manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/home/somewhere/VENV/lib/python3.10/site-packages/django/core/management/__init__.py", line 446, in execute_from_command_line
utility.execute()
File "/home/somewhere/VENV/lib/python3.10/site-packages/django/core/management/__init__.py", line 420, in execute
django.setup()
File "/home/somewhere/VENV/lib/python3.10/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/somewhere/VENV/lib/python3.10/site-packages/django/apps/registry.py", line 116, in populate
app_config.import_models()
File "/home/somewhere/VENV/lib/python3.10/site-packages/django/apps/config.py", line 304, in import_models
self.models_module = import_module(models_module_name)
File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 883, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "/home/somewhere/trucksys/truck/models.py", line 7, in <module>
class I_Articulos(models.Model):
File "/home/somewhere/trucksys/truck/models.py", line 15, in I_Articulos
descuento_directo = models.CharField('Descuento_Directo', max_length=20, null=False, blank=False)
TypeError: 'CharField' object is not callable
我应该怎么做才能解决这个问题?与什么有关?我是一名 Jr. Python 开发人员,所以如果你们中的一些有经验甚至经验丰富的人可以帮助我完成这个任务,那将会很有帮助。
下面一行是罪魁祸首:
descuento_maximo = models.CharField = models.CharField('Descuento_Maximo', max_length=20, null=False, blank=False)
你在这里给models.CharField
赋了一个新值,这样它就不再是对CharField
class的引用了,而是对 CharField
对象 的引用。您应该删除 = models.CharField
部分,因此:
descuento_maximo = models.CharField('Descuento_Maximo', max_length=20, null=False, blank=False)
但没有必要指定 null=False
和 blank=False
,这是默认情况。
class IArticulos(models.Model):
pais = models.CharField('Pais', max_length=30)
grupo_economico = models.CharField('Grupo_Economico', max_length=30)
empresa = models.CharField('Empresa', max_length=30)
sucursal = models.CharField('Sucursal', max_length=30)
almacenado = models.CharField('Almacenado', max_length=30)
id_rubro = models.FloatField('id_rubro', default=0, validators=[MinValueValidator(0), MaxValueValidator(99999)], unique=True)
descuento_maximo = models.CharField('Descuento_Maximo', max_length=20)
descuento_directo = models.CharField('Descuento_Directo', max_length=20)
unidad_minima_venta = models.DecimalField('Unidad_Minima_Venta', max_digits=15, decimal_places=4)
cantidad_unidades_unidad_venta = models.DecimalField('Cant_U_UV', max_length=30)
unidad_venta = models.CharField('Unidad_Venta', max_length=30)
descripcion_articulo = models.CharField('Descripcion_Articulo', max_length=100)
codigo_articulo = models.CharField('Codigo_articulo', max_length=30)
codigo_busqueda = models.CharField('Codigo_busqueda', max_length=30)
id_divisiona = models.CharField('id_divisiona', max_length=20)
id_segmento = models.CharField('id_segmento', max_length=20)
id_subrublo = models.CharField('id_subrublo', max_length=20)
id_linea = models.CharField('Pais', max_length=20)
tipo_item = models.PositiveIntegerField('tipo_item', default=0, validators=[MinValueValidator(0), MaxValueValidator(99999)])
combo_calcula_stock = models.CharField('combo_calcula_stock', max_length=30)
vc_fechahora_ultima_modificacion = models.DateTimeField('vc_fechahora_ultima_modificacion')
status = models.PositiveIntegerField('Status', default=0, validators=[MinValueValidator(0), MaxValueValidator(99999)])
activo = models.CharField('Activo', max_length=1)
fechahora_ultima_modificacion = models.DateTimeField('Pais')
Note: Models in Django are written in PascalCase, not snake_case,
so you might want to rename the model from I_Articulos
to IArticulos
.
检查第 7 个模型字段,'models.CharField =' 我认为是打字错误?
descuento_maximo = models.CharField = models.CharField('Descuento_Maximo', max_length=20, null=False, blank=False)
这是我的 models.py 来自我的应用程序,django 版本是 4.0.4,我的 python 版本是 3.10.4。我制作了所有模型,并在制作 makemigrations 以生成数据库后给出了错误代码。
from enum import unique
from django.db import models
from django.utils import timezone
from django.core.validators import MinValueValidator, MaxValueValidator
# Create your models here.
class I_Articulos(models.Model):
pais = models.CharField('Pais', max_length=30, null=False, blank=False)
grupo_economico = models.CharField('Grupo_Economico', max_length=30, null=False, blank=False)
empresa = models.CharField('Empresa', max_length=30, null=False, blank=False)
sucursal = models.CharField('Sucursal', max_length=30, null=False, blank=False)
almacenado = models.CharField('Almacenado', max_length=30, null=False, blank=False)
id_rubro = models.FloatField('id_rubro', null=False, blank=False, default=0, validators=[MinValueValidator(0), MaxValueValidator(99999)], unique=True)
descuento_maximo = models.CharField = models.CharField('Descuento_Maximo', max_length=20, null=False, blank=False)
descuento_directo = models.CharField('Descuento_Directo', max_length=20, null=False, blank=False)
unidad_minima_venta = models.DecimalField('Unidad_Minima_Venta', max_digits=15, decimal_places=4, null=False, blank=False)
cantidad_unidades_unidad_venta = models.DecimalField('Cant_U_UV', max_length=30, null=False, blank=False)
unidad_venta = models.CharField('Unidad_Venta', max_length=30, null=False, blank=False)
descripcion_articulo = models.CharField('Descripcion_Articulo', max_length=100, null=False, blank=False)
codigo_articulo = models.CharField('Codigo_articulo', max_length=30, null=False, blank=False)
codigo_busqueda = models.CharField('Codigo_busqueda', max_length=30, null=False, blank=False)
id_divisiona = models.CharField('id_divisiona', max_length=20, null=False, blank=False)
id_segmento = models.CharField('id_segmento', max_length=20, null=False, blank=False)
id_subrublo = models.CharField('id_subrublo', max_length=20, null=False, blank=False)
id_linea = models.CharField('Pais', max_length=20, null=False, blank=False)
tipo_item = models.PositiveIntegerField('tipo_item', null=False, blank=False, default=0, validators=[MinValueValidator(0), MaxValueValidator(99999)])
combo_calcula_stock = models.CharField('combo_calcula_stock', max_length=30, null=False, blank=False)
vc_fechahora_ultima_modificacion = models.DateTimeField('vc_fechahora_ultima_modificacion', null=False, blank=False)
status = models.PositiveIntegerField('Status', null=False, blank=False, default=0, validators=[MinValueValidator(0), MaxValueValidator(99999)])
activo = models.CharField('Activo', max_length=1, null=False, blank=False)
fechahora_ultima_modificacion = models.DateTimeField('Pais', null=False, blank=False)
然后我 运行 python3 manage.py makemigrations 来生成我的数据库,但是给我这个错误:
(VENV) byakenda@byakenda-G5-5587:~/Documents/somewhere/trucksys$ python3 manage.py makemigrations
Traceback (most recent call last):
File "/home/somewhere/trucksys/manage.py", line 22, in <module>
main()
File "/home/somewhere/trucksys/manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/home/somewhere/VENV/lib/python3.10/site-packages/django/core/management/__init__.py", line 446, in execute_from_command_line
utility.execute()
File "/home/somewhere/VENV/lib/python3.10/site-packages/django/core/management/__init__.py", line 420, in execute
django.setup()
File "/home/somewhere/VENV/lib/python3.10/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/somewhere/VENV/lib/python3.10/site-packages/django/apps/registry.py", line 116, in populate
app_config.import_models()
File "/home/somewhere/VENV/lib/python3.10/site-packages/django/apps/config.py", line 304, in import_models
self.models_module = import_module(models_module_name)
File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 883, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "/home/somewhere/trucksys/truck/models.py", line 7, in <module>
class I_Articulos(models.Model):
File "/home/somewhere/trucksys/truck/models.py", line 15, in I_Articulos
descuento_directo = models.CharField('Descuento_Directo', max_length=20, null=False, blank=False)
TypeError: 'CharField' object is not callable
我应该怎么做才能解决这个问题?与什么有关?我是一名 Jr. Python 开发人员,所以如果你们中的一些有经验甚至经验丰富的人可以帮助我完成这个任务,那将会很有帮助。
下面一行是罪魁祸首:
descuento_maximo = models.CharField = models.CharField('Descuento_Maximo', max_length=20, null=False, blank=False)
你在这里给models.CharField
赋了一个新值,这样它就不再是对CharField
class的引用了,而是对 CharField
对象 的引用。您应该删除 = models.CharField
部分,因此:
descuento_maximo = models.CharField('Descuento_Maximo', max_length=20, null=False, blank=False)
但没有必要指定 null=False
和 blank=False
,这是默认情况。
class IArticulos(models.Model):
pais = models.CharField('Pais', max_length=30)
grupo_economico = models.CharField('Grupo_Economico', max_length=30)
empresa = models.CharField('Empresa', max_length=30)
sucursal = models.CharField('Sucursal', max_length=30)
almacenado = models.CharField('Almacenado', max_length=30)
id_rubro = models.FloatField('id_rubro', default=0, validators=[MinValueValidator(0), MaxValueValidator(99999)], unique=True)
descuento_maximo = models.CharField('Descuento_Maximo', max_length=20)
descuento_directo = models.CharField('Descuento_Directo', max_length=20)
unidad_minima_venta = models.DecimalField('Unidad_Minima_Venta', max_digits=15, decimal_places=4)
cantidad_unidades_unidad_venta = models.DecimalField('Cant_U_UV', max_length=30)
unidad_venta = models.CharField('Unidad_Venta', max_length=30)
descripcion_articulo = models.CharField('Descripcion_Articulo', max_length=100)
codigo_articulo = models.CharField('Codigo_articulo', max_length=30)
codigo_busqueda = models.CharField('Codigo_busqueda', max_length=30)
id_divisiona = models.CharField('id_divisiona', max_length=20)
id_segmento = models.CharField('id_segmento', max_length=20)
id_subrublo = models.CharField('id_subrublo', max_length=20)
id_linea = models.CharField('Pais', max_length=20)
tipo_item = models.PositiveIntegerField('tipo_item', default=0, validators=[MinValueValidator(0), MaxValueValidator(99999)])
combo_calcula_stock = models.CharField('combo_calcula_stock', max_length=30)
vc_fechahora_ultima_modificacion = models.DateTimeField('vc_fechahora_ultima_modificacion')
status = models.PositiveIntegerField('Status', default=0, validators=[MinValueValidator(0), MaxValueValidator(99999)])
activo = models.CharField('Activo', max_length=1)
fechahora_ultima_modificacion = models.DateTimeField('Pais')
Note: Models in Django are written in PascalCase, not snake_case, so you might want to rename the model from
toI_Articulos
IArticulos
.
检查第 7 个模型字段,'models.CharField =' 我认为是打字错误?
descuento_maximo = models.CharField = models.CharField('Descuento_Maximo', max_length=20, null=False, blank=False)