'Entity Framework Core : change column type from string to DateTime

I am new to Entity Framework Core and I want to change a column type from string to DateTime using migrations.

The property I want to change is:

public string AppointmentDate { get; set; }

to be:

public DateTime AppointmentDate { get; set; }

Once I've made the model change, I run

dotnet ef migrations add appointment_date_type

which results in a bunch of CreateTable statements i.e:

public partial class appointment_date_type : Migration
{
    protected override void Up(MigrationBuilder migrationBuilder)
    {
        migrationBuilder.CreateTable(
            name: "JobSummaries",
            columns: table => new
            {
                Id = table.Column<Guid>(nullable: false),
                LocalChanges = table.Column<bool>(nullable: false),
                CloudId = table.Column<Guid>(nullable: true),
                SurveyorId = table.Column<string>(nullable: true),
                ContractName = table.Column<string>(nullable: true),
                InstructionType = table.Column<string>(nullable: true),
                SysRef = table.Column<string>(nullable: true),
                JobStatus = table.Column<int>(nullable: false),
                PropertyAddress = table.Column<string>(nullable: true),
                TypeName = table.Column<string>(nullable: true),
                StyleName = table.Column<string>(nullable: true),
                PropertyPriceType = table.Column<string>(nullable: true),
                PropertyPrice = table.Column<string>(nullable: true),
                AppointmentDate = table.Column<DateTime>(nullable: false),
                AppointmentWindowStartTime = table.Column<string>(nullable: true),
                AppointmentWindowEndTime = table.Column<string>(nullable: true),
                AppointmentEta = table.Column<string>(nullable: true),
                ContactCallAheadIsRequired = table.Column<bool>(nullable: false),
                ContactName = table.Column<string>(nullable: true),
                ContactTelephoneNumber = table.Column<string>(nullable: true),
                ContactType = table.Column<string>(nullable: true),
                ContactCallAheadLeadTime = table.Column<string>(nullable: true),
                IsKeyCollectionOrReturnRequired = table.Column<bool>(nullable: false),
                KeyInformationDescription = table.Column<string>(nullable: true),
                JobVersion = table.Column<string>(nullable: true),
                Latitude = table.Column<double>(nullable: true),
                Longitude = table.Column<double>(nullable: true),
                LastSync = table.Column<long>(nullable: false),
                PhotosLastSync = table.Column<long>(nullable: false),
                DocumentsLastSync = table.Column<long>(nullable: false),
                KeepJobUntil = table.Column<DateTime>(nullable: false)
            },
            constraints: table =>
            {
                table.PrimaryKey("PK_JobSummaries", x => x.Id);
            });

Is this correct? Should it not generate a statement to alter the column type?

If not, how do I write a migration for the column type from string to DateTime?

The project I'm working on is using Entity Framework Core v3.1.22 and SQLite.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source