1

I am using this code:

def saveUploadedInventory(self, inventory_file,user_id):
        print "Inventory File"
        with open('uploaded_inventory_sheet.csv','wb+') as destination:
            for chunk in inventory_file.chunks():
                destination.write(chunk)
        print "Inventory Saved."
        f = open('uploaded_inventory_sheet.csv','rb')


        with open('uploaded_inventory_sheet.csv') as f:
            next(f)
            content = StringIO('\n'.join(line for line in f))
            self.cur.copy_from(content,'fk_payment_temp', sep=',', null='null', columns=('settlement_ref_no', 'order_type', 'fulfilment_type', 'seller_sku', 
            'wsn', 'order_id', 'order_item_id', 'order_date', 'dispatch_date', 'delivery_date', 
            'cancellation_date', 'settlement_date', 'order_status', 'quantity', 'order_item_value', 
            'sale_transaction_amount', 'discount_transaction_amount', 'refund', 
            'protection_fund', 'total_marketplace_fee', 'service_tax', 'swach_bharat_cess', 
            'settlement_value', 'commission_rate', 'commission', 'payment_rate', 
            'payment_fee', 'fee_discount', 'cancellation_fee', 'fixed_fee', 'emi_fee', 
            'total_weight', 'weight_type', 'shipping_fee', 'reverse_shipping_fee', 
            'shipping_zone', 'token_of_apology', 'pick_and_pack_fee', 'storage_fee', 
            'removal_fee', 'invoice_id', 'invoice_date', 'invoice_amount', 'sub_category', 
            'total_offer_amount', 'my_offer_share', 'flipkart_offer_share'))
        f.close()

It is giving error:

    DataError at /upload/
invalid input syntax for type date: ""
CONTEXT:  COPY fk_payment_temp, line 1, column cancellation_date: ""

there is lots of date column dont have any value.

my table structure is:

CREATE TABLE fk_payment_temp
(
  id serial NOT NULL,
  settlement_ref_no character varying,
  order_type character varying,
  fulfilment_type character varying,
  seller_sku character varying,
  wsn character varying,
  order_id character varying,
  order_item_id character varying,
  order_date timestamp without time zone,
  dispatch_date date default null,
  delivery_date date default null,
  cancellation_date date default null,
  settlement_date date,
  order_status character varying,
 .....

Any body can help me to solve this problem .

either changing python code or changing postgresql structure ?

to converting date to varchar is least option.

5
  • Try changing Date Fields to CharField and null True. Commented Jan 14, 2016 at 10:13
  • then it is done . but i have instruction to not to change data type Commented Jan 14, 2016 at 10:16
  • How are you using Django? Do you have model for the table? Commented Jan 14, 2016 at 10:36
  • no i am not using any model Commented Jan 14, 2016 at 10:41
  • Try passing parameter null="" or null = '""' . Commented Jan 14, 2016 at 11:28

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.