title: MySqlException: Field 'id' doesn't have a default value - Entity Framework Core 2.1
body: <p>I'm new to ASP.NET Core MVC. I'm getting error on inserting data to MySQL with entity framework Core.
  While debugging i got id in minus(-2147482645) assigned by context.Why id is assigned by EF? How to resolve this error? Table in MySQL id column is NOTNULL, PK and Auto Increment set default.
  <a href="https://i.stack.imgur.com/rPJ4w.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rPJ4w.png" alt="enter image description here"></a></p>
  
  <p><strong>Here is my DBContextFile</strong></p>
  
  <pre><code>    {
          public AppDbContext(DbContextOptions&lt;AppDbContext&gt; options)
              : base(options)
          { }
  
          public DbSet&lt;PCBDesign&gt; pCBDesigns { get; set; }
  
  
  
          protected override void OnModelCreating(ModelBuilder modelBuilder)
          {
              base.OnModelCreating(modelBuilder);
          }
      }
  </code></pre>
  
  <p><strong>Here is My Class</strong></p>
  
  <pre><code>    {
  
          [Key]
          public int id { get; set; }
          public string userId { get; set; }
          public string desginNo { get; set; }
          public DateTime Crdate { get; set; }
          public string name { get; set; }
          public string contact { get; set; }
          public string notes { get; set; }
      }
  </code></pre>
  
  <p><strong>After call</strong> context.SaveChanges();
  <strong>Getting Error:</strong> </p>
  
  <pre><code>Microsoft.EntityFrameworkCore.DbUpdateException: An error occurred while updating the entries. See the inner exception for details. ---&gt; MySql.Data.MySqlClient.MySqlException: Field 'id' doesn't have a default value ---&gt; MySql.Data.MySqlClient.MySqlException: Field 'id' doesn't have a default value
  
  </code></pre>
  
  <p><strong>Query of table creation:</strong></p>
  
  <pre><code>DROP TABLE IF EXISTS `pcbdesigns`;
  /*!40101 SET @saved_cs_client     = @@character_set_client */;
  /*!50503 SET character_set_client = utf8mb4 */;
  CREATE TABLE `pcbdesigns` (
    `id` int NOT NULL AUTO_INCREMENT,
    `userId` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci,
    `desginNo` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci,
    `Crdate` datetime NOT NULL,
    `name` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci,
    `contact` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci,
    `notes` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci,
    PRIMARY KEY (`id`)
  ) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
  /*!40101 SET character_set_client = @saved_cs_client */;
  
  --
  -- Dumping data for table `pcbdesigns`
  --
  
  LOCK TABLES `pcbdesigns` WRITE;
  /*!40000 ALTER TABLE `pcbdesigns` DISABLE KEYS */;
  INSERT INTO `pcbdesigns` VALUES ();
  /*!40000 ALTER TABLE `pcbdesigns` ENABLE KEYS */;
  UNLOCK TABLES;`
  </code></pre>