1

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
  • 77
  • 1
  • 10

4 Answers4

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
  • 135
  • 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

0

you have a duplicated object "AspNetRoles", you try to create table (object) with same name of an object who exist on Data Base already.

taha-mou
  • 1
  • 1
  • Welcome to Stack Overflow. Why are you answering a 3,5 year old question? It was probably resolved 3,5 years ago.... You should check the dates of questions. Also: please check if nobody else has written the same answer before you. – JHBonarius Dec 21 '22 at 10:11