Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to specify column name with spaces in django

How can we specify column names with spaces in django model?

I have an excel sheet with column names Invoice date and Sales Value. I cannot have a column name as "Invoice Value" in django model. It is throwing a syntax error. If I specify my column name as "Invoice_Date" the django model is creating a column with the same name. But I could not import the excel file with the column name "Invoice Date". I don't want to replace my white spaces in excel column names with an underscore. Please help to resolve this

class total(models.Model):
    Invoice_Date = models.DateField(db_column ='Invoice Date')
    Sales_Value = models.IntegerField(db_column ='Sales Value')
    objects = models.Manager()
    class Meta:
        abstract = True
        managed = True
    def __str__(self):
        return 'Invoice_Date : {0} Sales_Value : {1}'.format(self.Invoice_Date, self.Sales_Value)
like image 358
vicky Avatar asked Oct 30 '25 04:10

vicky


1 Answers

I resolved it as follows:

Reported_Date =models.CharField(max_length=30,db_column='Reported Date')
like image 167
JHON ALEXANDER PORRAS TORRES Avatar answered Nov 02 '25 19:11

JHON ALEXANDER PORRAS TORRES



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!