Cannot insert the value NULL into column 'customer_id' but customer_id does have value

Kestal

I'm using MSSQL bulk function to insert data into the database. The column customer_id does exist in the table.

When I debug and see the values that's in table.rows.push(map), I can see property customer_id and it has a integer value. I also debugged await request.bulk(table) and I can see property customer_id and it has a integer value.

I don't know why I'm getting the following error message.

Cannot insert the value NULL into column 'customer_id', table 'api.dbo.givers'; column does not allow nulls. INSERT fails."

try {
  let results = [];
  var response = fs
    .createReadStream('C:\\data\\givers.csv')
    .pipe(parse({ delimiter: ',', from_line: 2 }))
    .on('data', function (row) {
      results.push(row);
    });
  return new Promise(function (resolve, reject) {
    response.on('end', async () => {
      let pool = await sql.connect(connectionConfig);
      const table = new sql.Table('givers');
      table.create = false;
      table.columns.add('customer_id', sql.Int, { nullable: false });
      table.columns.add('source_giver_id', sql.VarChar, { nullable: false });
      ...

      results.forEach((row) => {
        const map = [];
        map['customer_id'] = customer_id;
        map['last_updated'] = moment(new Date()).format('YYYY-MM-DD HH:mm:ss');
        ...
        table.rows.push(map);
      });

      const request = new sql.Request(pool);
      await request.bulk(table); //error get's thrown here

      resolve(results.length);
    });
    response.on('error', reject);
  });
} catch (err) {
  if (err) return err;
}
Navneil Naicker

I was able to replicate this issue. I've been playing around and when I change const map = []; to const map = {}; it worked. I don't know why const map = []; didn't work because table.rows is an interface of interface Array<T> extends RelativeIndexable<T> {}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

cannot insert null value in id column

column reference "customer_id" is ambiguous

get only one value for customer_ID where multiple rows for where

SQL insert error: Cannot insert the value NULL into column 'Id'

NodeJs TypeError: Cannot read property 'Customer_id' of undefined

Web API error: "Cannot insert the value NULL into column 'Id'

Entity Framework Non Identity - Cannot insert the value NULL into column 'ID'

#1072 - Key column 'Customer_ID' doesn't exist in table

Cannot insert NULL into column while value is not null

Cannot insert the value NULL into column 'Discriminator', table '...AspNetUsers'; column does not allow nulls. INSERT fails

Cannot insert the value NULL into column X, column X does not allow nulls. INSERT fails.

Cannot insert the value NULL into column 'DeletedDatabaseRecord',...; column does not allow nulls. INSERT fails

SqlException: Cannot insert the value NULL into column 'x'; column does not allow nulls. INSERT fails

Cannot insert 'NULL' value into SQL Server column

EFCore Cannot insert the value NULL into column

SqlBulkCopy Cannot insert the value NULL into column

SQL: Cannot insert the value NULL into column 'ExampleID'

The procedure throws error "Can not insert null in"CUSTOMER"."CUST_ID" although the value is not null

"Cannot insert the value NULL into column" despite value not being NULL

regex js for application[0].customer_id

'NoneType' object has no attribute 'customer_id'

How to fix: Cannot insert the value NULL into column, insert failed

Postgres error: null value in column "id" - during insert operation

Cannot insert the value NULL into column 'MaintenanceId', table '<tableName>'; column does not allow nulls. INSERT fails EF 6.1

Stripe : New customer created even when customer_id is not empty?

Cannot insert the value NULL into column (MS-SQL) with Store Procedure

ASP.NET Cannot insert the value NULL into column ‘name’

Cannot insert or update varchar empty/null value into always encrypted column

Query to return value based on min of another column and customer ID?

TOP Ranking

HotTag

Archive