I've got a problem when i try to add Record to a Table which contains only one column MandantId as integer primary key. This column is not auto-increment. When I try to add a Record I get the following error message: "23502: null value in column "mandantid" violates not-null constraint"
What i use:
- PostgreSQL 9.6
- EntityFramework 6.1.3
- EntityFramework6.Npgsql 3.1.1
- Npgsql 3.1.2
If I use a INSERT query like: _context.Database.ExecuteSqlCommand(string.Format("INSERT INTO public.mandant (mandantid) VALUES ({0});"), MandantId)); It works!
But I don't want to use a fix query. What I've already tried:
- With the Add() and SaveChanges() functions from EF, once with 0 and once valid integer, same error
- Removed all dependencies on Database and EF, same error
- Using an insert script, which worked
- Added an additional column named id as primary key as auto-increment, which worked. But then i have two unique keys.
This is my Databasemodel:
[Table("mandant", Schema = "public")]
public class MandantEdm
{
public MandantEdm()
{
}
[Key]
[Column("mandantid")]
public int MandantId { get; set; }
}
This is the context-class:
class LicenseContext : DbContext
{
public LicenseContext()
: base("MandantContext")
{
}
public virtual DbSet<MandantEdm> Mandants { get; set; }
}