question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Couldn't insert a record with nullable id

See original GitHub issue

TL;DR: Repository with the tests. More specifically:

Model:

public class Customer
{
    public int? Id { get; set; }
    public string Name { get; set; }
}

Test:

var col = _liteDatabase.GetCollection<Customer>();

var customer = new Customer
{
    Name = "John Doe",
};

col.Insert(customer);

Assert.True(col.Exists(x => x.Id == customer.Id));

Actually col.Insert throws an exception:

LiteDB.LiteException : Invalid BSON data type ‘Null’ on field ‘_id’.

Fails for both LiteDatabase and LiteRepository.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
padillahcommented, Nov 29, 2018

BTW: null and 0 are not the same. Null means it has not been set. 0 means it has been set… to 0.

I would think there’s a strong argument for Auto Increment Id properties to be int? so we know they have not been set.

0reactions
lbnascimentocommented, Feb 28, 2020

Hi! With the objective of organizing our issues, we are closing old unsolved issues. Please check the latest version of LiteDB and open a new issue if your problem/question/suggestion still applies. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot insert the value NULL into column 'id'?
When you created table you have not indicate ' ID ' column to be Auto Increment hence you get this error. By making...
Read more >
Can't insert a record with NULL value in nullable ...
When a record has a NULL value, or when I assign the NULL value by selecting the empty string, all works fine and...
Read more >
Cannot insert the value NULL into column and ...
[ProdID] [int] IDENTITY(1,1) NOT NULL. I am trying to insert the records into this prod table using the destination table values ,insert ......
Read more >
I'm Getting a Cannot Insert the Value NULL Into Column 'ID' ...
INSERT fails.” Something like this: Error: Cannot insert the value null into column ID. You look at your SQL statement first, to see...
Read more >
Msg 515 - Cannot insert the value NULL into column ' ...
As the message suggests, you are trying to insert a new record into a table and one of the columns is being assigned...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found