3

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");
}
6
  • Are you sure the error occurs on this specific migration? Because this migration has nothing to do with AspNetRoles as indicated in the error message. Commented May 4, 2019 at 8:08
  • No, it always arises ( Commented May 4, 2019 at 8:09
  • How many migrations do you have? and how long are they? I'm asking to see if it's possible to share them all. Commented May 4, 2019 at 8:11
  • At the moment, one, because I deleted the migration folder, it was not worth it? Commented May 4, 2019 at 8:15
  • 1
    stackoverflow.com/questions/24169140/… @pitten Commented May 4, 2019 at 8:39

4 Answers 4

3

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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

1 Comment

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.
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

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.