0

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");
}
Community
  • 1
  • 1
pitten
  • 67
  • 1
  • 9

3 Answers3

2

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.

Elvis Jr
  • 125
  • 6
0
  1. [Column(TypeName ="nvarchar(250)")] - Check the paranthese closing and Quotations(I rectified the error here)

  2. Delete the Migration

  3. Ad-Migration "InitialCreate"

  4. Update-Database -verbose

Nithya
  • 17
  • 2
0

There is already an object named 'AspNetRoles' in the database. You must delete 'AspNetRoles' databese with connections and then You must made update database again. if not again, make database name AspNetRoles1