Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing Primary Key using Entity Framework Core Migrations

I am trying to Change the Primary key of a table via Entity Framework Core Migrations:

protected override void Up(MigrationBuilder migrationBuilder)
{
        migrationBuilder.DropPrimaryKey(
            name: "PK_Permissions",
            table: "Permissions");
}

When I try to update the database I get the following error message:

To change the IDENTITY property of a column, the column needs to be dropped and recreated.

How can I update the database?

like image 575
Alexander Avatar asked May 05 '17 07:05

Alexander


People also ask

How do I use migrations in Entity Framework?

Step 1 − Before running the application you need to enable migration. Step 2 − Open Package Manager Console from Tools → NuGet Package Manger → Package Manger Console. Step 3 − Migration is already enabled, now add migration in your application by executing the following command.

How do I apply EF core migration?

Migrations are enabled by default in EF Core. They are managed by executing commands. If you have Visual Studio, you can use the Package Manager Console (PMC) to manage migrations. Alternatively, you can use a command line tool to execute Entity Framework CLI commands to create a migration.


1 Answers

I have found a solution: This seems to be a bug in EF Core 1.1

I changed the Migration file.

More Information about this can be found here: https://thisworksonmymachine.com/2017/02/13/ef-core-the-setup-part-4/

like image 86
Alexander Avatar answered Sep 28 '22 11:09

Alexander