title: Entity Framework Core: Scaffolding to Avoid Data Loss after to change Model/Entity
body: <p>I had the following Model:</p>
  
  <pre><code>public class Promotion : BaseModel
  {
      [Required]
      public string Description { get; set; }
  
      [Required]
      public string Market { get; set; }
  
      [Required]
      public double Price { get; set; }
  }
  </code></pre>
  
  <p>It was created a Migration that was updated to the database. And some <em>promotions</em> was inserted on the database. But I needed to change the Promotion Model to this:</p>
  
  <pre><code>public class Promotion : BaseModel
  {
      [Required]
      public string Description { get; set; }
  
      [Required]
      public Market Market { get; set; }
  
      [Required]
      public double Price { get; set; }
  }
  
  public class Market : BaseModel
  {
      [Required]
      public string Name { get; set; }
  
      [Required]
      public string Adress { get; set; }
  }
  </code></pre>
  
  <p>When I added a new Migration, I got the alert: "An operation was scaffolding that may result in the loss of data. Please review the migrations for accuracy."</p>
  
  <p>That's the auto generated Up method of the new Migration:</p>
  
  <pre><code>protected override void Up(MigrationBuilder migrationBuilder)
      {
          migrationBuilder.DropColumn(
              name: "Market",
              table: "Promotions");
  
          migrationBuilder.AddColumn&lt;Guid&gt;(
              name: "MarketId",
              table: "Promotions",
              nullable: false,
              defaultValue: new Guid("00000000-0000-0000-0000-000000000000"));
  
          migrationBuilder.CreateTable(
              name: "Markets",
              columns: table =&gt; new
              {
                  Id = table.Column&lt;Guid&gt;(nullable: false),
                  Adress = table.Column&lt;string&gt;(nullable: false),
                  CreatedAt = table.Column&lt;DateTime&gt;(nullable: false),
                  DeletedAt = table.Column&lt;DateTime&gt;(nullable: false),
                  Name = table.Column&lt;string&gt;(nullable: false),
                  UpdatedAt = table.Column&lt;DateTime&gt;(nullable: false)
              },
              constraints: table =&gt;
              {
                  table.PrimaryKey("PK_Markets", x =&gt; x.Id);
              });
  
          migrationBuilder.CreateIndex(
              name: "IX_Promotions_MarketId",
              table: "Promotions",
              column: "MarketId");
  
          migrationBuilder.AddForeignKey(
              name: "FK_Promotions_Markets_MarketId",
              table: "Promotions",
              column: "MarketId",
              principalTable: "Markets",
              principalColumn: "Id",
              onDelete: ReferentialAction.Cascade);
      }
  </code></pre>
  
  <p>How can I update the database without lose data?</p>