@@ -0,0 +1,40 @@
1+using Microsoft.EntityFrameworkCore.Migrations;
2+
3+#nullable disable
4+
5+namespace FieldOps.Api.Data.Migrations
6+{
7+ /// <inheritdoc />
8+ public partial class RenameCustomerPhone : Migration
9+ {
10+ /// <inheritdoc />
11+ protected override void Up(MigrationBuilder migrationBuilder)
12+ {
13+ migrationBuilder.DropColumn(
14+ name: "Phone",
15+ table: "Customers");
16+
17+ migrationBuilder.AddColumn<string>(
18+ name: "PrimaryPhone",
19+ table: "Customers",
20+ type: "nvarchar(32)",
21+ maxLength: 32,
22+ nullable: true);
The cause: this is a rename done as "delete the old column, then add a new one", and deleting a column deletes the data in it. When this runs in production, every existing customer's phone number is permanently erased, and PrimaryPhone starts empty for everyone. The team rules say renames must use RenameColumn so existing rows keep their data.
Suggested fix: Replace the DropColumn/AddColumn pair in Up with migrationBuilder.RenameColumn(name: "Phone", table: "Customers", newName: "PrimaryPhone");.
23+ }
24+
25+ /// <inheritdoc />
26+ protected override void Down(MigrationBuilder migrationBuilder)
27+ {
28+ migrationBuilder.DropColumn(
29+ name: "PrimaryPhone",
30+ table: "Customers");
31+
32+ migrationBuilder.AddColumn<string>(
33+ name: "Phone",
34+ table: "Customers",
35+ type: "nvarchar(32)",
36+ maxLength: 32,
37+ nullable: true);
The rollback (Down) has the same problem. It drops PrimaryPhone and adds an empty Phone column. If the team ever rolls this migration back, all phone numbers entered since the deploy are lost too.
Suggested fix: In Down, use migrationBuilder.RenameColumn(name: "PrimaryPhone", table: "Customers", newName: "Phone");.
38+ }
39+ }
40+}
The migration is added without its designer file (20261120100000_RenameCustomerPhone.Designer.cs), and the model snapshot is not updated. Without the designer file, EF may not discover or apply the migration. A stale snapshot also makes the next generated migration try to make this change again. The team rules require both files.
Suggested fix: Generate the migration with dotnet ef migrations add RenameCustomerPhone so the designer file and snapshot update are created. Then edit Up and Down to use RenameColumn, and commit all three files.