-
Notifications
You must be signed in to change notification settings - Fork 227
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migration not applying after upgrading to .NET 5 #1600
Comments
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@danielbecroft sorry for not commenting on this sooner... I've tried generating migrations with EF Core 5.0, 3.1 and 3.0: EF Core 3.0protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<DateTimeOffset>(
name: "CreatedOn",
table: "Blogs",
nullable: false,
defaultValueSql: "now()",
oldClrType: typeof(DateTime),
oldType: "timestamp without time zone",
oldDefaultValueSql: "now()");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<DateTime>(
name: "CreatedOn",
table: "Blogs",
type: "timestamp without time zone",
nullable: false,
defaultValueSql: "now()",
oldClrType: typeof(DateTimeOffset),
oldDefaultValueSql: "now()");
} EF Core 3.1protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<DateTimeOffset>(
name: "CreatedOn",
table: "Blogs",
nullable: false,
defaultValueSql: "now()",
oldClrType: typeof(DateTime),
oldType: "timestamp without time zone",
oldDefaultValueSql: "now()");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<DateTime>(
name: "CreatedOn",
table: "Blogs",
type: "timestamp without time zone",
nullable: false,
defaultValueSql: "now()",
oldClrType: typeof(DateTimeOffset),
oldDefaultValueSql: "now()");
} EF Core 5.0protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<DateTimeOffset>(
name: "CreatedOn",
table: "Blogs",
type: "timestamp with time zone",
nullable: false,
defaultValueSql: "now()",
oldClrType: typeof(DateTime),
oldType: "timestamp without time zone",
oldDefaultValueSql: "now()");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<DateTime>(
name: "CreatedOn",
table: "Blogs",
type: "timestamp without time zone",
nullable: false,
defaultValueSql: "now()",
oldClrType: typeof(DateTimeOffset),
oldType: "timestamp with time zone",
oldDefaultValueSql: "now()");
} I can consistently see |
Hi @roji , |
Closing as per #1663 (comment) |
- added types to migrations to fix npgsql/efcore.pg#1600 - updated to latest npgsql - added null cheks to seed data processing
…le (#37) - added types to migrations to fix npgsql/efcore.pg#1600 - updated to latest npgsql - added null cheks to seed data processing
We have an application that was started under .NET Core 3.0, and has had a number of migrations generated and applied.
For some of our models, we added "shadow properties" like the below, that we added for automatic tracking of auditing and the like. One of the example fields is the
CreatedOn
field:After adding this field, we changed this from
DateTime
toDateTimeOffset
, and the migration was generated as:This migration correctly applies under .NET Core 3.1. However, when running the migration under .NET 5, the statement is a no-op. The migration is recorded as run during the
.Migrate()
phase, but nothing else happens. The datatype of the field is not changed.NOTE: This matches the committed version of our migration. Attempting to replicate this issue, the migration includes an
oldType: "timestamp without time zone"
line. If I include this line, both versions correctly apply the migration. Removing this line causes .NET 5 to not apply the migration, but .NET Core 3.1 does.Running
dotnet ef migrations script
between the two migrations gives the following:.NET Core 3.1
.NET 5
Was there a fix where a previous version would not include the
oldType
line in the migration? (trying to work out why this line would not have been included in the original migration)?Is this a bug where we have a migration that no longer applies between the major versions?
I've setup a basic repository with the example migrations here.
The text was updated successfully, but these errors were encountered: