我在Django项目中有一个称为OHEM的SAP Business One模型,但是该ERP允许为每个公司创建自定义字段。
实际上,我有一个公司的管理员,另一个人想使用它们,但是当在公司“ B”数据库中运行代码时,我有一个下警告:
“ U_INT_EMPLOYEE_CODE”列的名称不存在。 (207)
公司“ A”有很多用户字段,公司“ B”有另一个用户针对同一模型使用不同的字段,并且想对两者使用相同的代码
class Ohem(models.Model):
empid = models.IntegerField(db_column='empID', primary_key=True) # Field name made lowercase.
lastname = models.CharField(db_column='lastName', max_length=50, blank=True, null=True) # Field name made lowercase.
firstname = models.CharField(db_column='firstName', max_length=50, blank=True, null=True) # Field name made lowercase.
middlename = models.CharField(db_column='middleName', max_length=50, blank=True, null=True) # Field name made lowercase.
sex = models.CharField(max_length=1, blank=True, null=True)
jobtitle = models.CharField(db_column='jobTitle', max_length=20, blank=True, null=True) # Field name made lowercase.
type = models.IntegerField(blank=True, null=True)
dept = models.SmallIntegerField(blank=True, null=True)
branch = models.SmallIntegerField(blank=True, null=True)
# Company A fields
u_int_cod_empleado = models.IntegerField(db_column='U_INT_COD_EMPLEADO', blank=True, null=True) # Field name made lowercase.
u_hbt_contrasena = models.CharField(db_column='U_HBT_Contrasena', max_length=100, blank=True, null=True) # Field name made lowercase.
u_hbt_cardcode = models.CharField(db_column='U_HBT_CardCode', max_length=15, blank=True, null=True) # Field name made lowercase.
u_fechactualisap = models.DateTimeField(db_column='U_FechActualiSAP', blank=True, null=True) # Field name made lowercase.
u_fechactualimovil = models.DateTimeField(db_column='U_FechActualiMovil', blank=True, null=True) # Field name made lowercase.}
# Company B fields
u_hbt_cardcode = models.CharField(db_column='U_HBT_CardCode', max_length=15, blank=True, null=True) # Field name made lowercase.
u_internalusercode = models.DateTimeField(db_column='U_INTUSER_COD', blank=True, null=True) # Field name made lowercase.
我想在SQL执行之前删除此字段,但是Model._meta.fields也是ImmutableList和Model._meta.concrete_fields