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");
}
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.