Error migrating to Entity Framework, the table is not updated

asp.net-core c# ef-migrations entity-framework-core

Question

I add a new field to the class User - IdentiyUser, after which I ran

add-migration [name]

This creates a migration file, but after executing update-database command, I get two errors.

I tried to delete the database and create it with its migration, the database is created, the column with my field is added, but the errors are the same

Failed executing DbCommand (12ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
CREATE TABLE [AspNetRoles]
(
[Id] nvarchar(450) NOT NULL,
[Name] nvarchar(256) NULL,
[NormalizedName] nvarchar(256) NULL,
[ConcurrencyStamp] nvarchar(max) NULL,
CONSTRAINT [PK_AspNetRoles] PRIMARY KEY ([Id])
);

There is already an object named 'AspNetRoles' in the database.

Migration

protected override void Up(MigrationBuilder migrationBuilder)
{
    migrationBuilder.RenameColumn(
            name: "Balance",
            table: "AspNetUsers",
            newName: "Age");
}

protected override void Down(MigrationBuilder migrationBuilder)
{
    migrationBuilder.RenameColumn(
            name: "Age",
            table: "AspNetUsers",
            newName: "Balance");
}
1
0
5/4/2019 7:50:30 AM

Popular Answer

when you delete the migrations to create just one you should delete the database because the tables are created and you get that error. The faster solution in this case is delete all migrations folder and database and start all over.

1
5/4/2019 5:51:34 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow