Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9232685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:22:21+00:00 2026-06-18T06:22:21+00:00

I am creating this model as part of my code first entity framework public

  • 0

I am creating this model as part of my code first entity framework

public class NewUserRegistration
{
    [Key]
    public int NewUserRegistrationId { get; set; }    
}

Using the Update-Database -Verbose -Force command in the Package Manger ConsoleI get this exception during the this bit of the update Applying automatic migration: 201211252223088_AutomaticMigration.

ALTER TABLE [dbo].[NewUserRegistration] ADD [NewUserRegistrationId]
[int] NOT NULL IDENTITY System.Data.SqlClient.SqlException
(0x80131904): Multiple identity columns specified for table
‘NewUserRegistration’. Only one identity column per table is allowed.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception,
Boolean breakConnection, Action1 wrapCloseInAction) at
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException
exception, Boolean breakConnection, Action
1 wrapCloseInAction) at
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject
stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) at
System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior,
SqlCommand cmdHandler, SqlDataReader dataStream,
BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject
stateObj, Boolean& dataReady) at
System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String
methodName, Boolean async, Int32 timeout) at
System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource1
completion, String methodName, Boolean sendToPipe, Int32 timeout,
Boolean asyncWrite) at
System.Data.SqlClient.SqlCommand.ExecuteNonQuery() at
System.Data.Entity.Migrations.DbMigrator.ExecuteSql(DbTransaction
transaction, MigrationStatement migrationStatement) at
System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.ExecuteSql(DbTransaction
transaction, MigrationStatement migrationStatement) at
System.Data.Entity.Migrations.DbMigrator.ExecuteStatements(IEnumerable
1
migrationStatements) at
System.Data.Entity.Migrations.Infrastructure.MigratorBase.ExecuteStatements(IEnumerable1
migrationStatements) at
System.Data.Entity.Migrations.DbMigrator.ExecuteOperations(String
migrationId, XDocument targetModel, IEnumerable
1 operations, Boolean
downgrading, Boolean auto) at
System.Data.Entity.Migrations.DbMigrator.AutoMigrate(String
migrationId, XDocument sourceModel, XDocument targetModel, Boolean
downgrading) at
System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.AutoMigrate(String
migrationId, XDocument sourceModel, XDocument targetModel, Boolean
downgrading) at
System.Data.Entity.Migrations.DbMigrator.Upgrade(IEnumerable1
pendingMigrations, String targetMigrationId, String lastMigrationId)
at
System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.Upgrade(IEnumerable
1
pendingMigrations, String targetMigrationId, String lastMigrationId)
at System.Data.Entity.Migrations.DbMigrator.Update(String
targetMigration) at
System.Data.Entity.Migrations.Infrastructure.MigratorBase.Update(String
targetMigration) at
System.Data.Entity.Migrations.Design.ToolingFacade.UpdateRunner.RunCore()
at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.Run()
ClientConnectionId:a39395da-5f2b-48e0-bdac-b48d75a68c68 Multiple
identity columns specified for table ‘NewUserRegistration’. Only one
identity column per table is allowed.

There is plainly only one Identity Column specified. So why is this the case?

When I do this I get no exception.

public class NewUserRegistration
{
    [Key]
    public int Id { get; set; }    
}

Any thoughts on why this is the case?

EDIT

I should say that I am changing the name of the key. The comments say that you can’t just do this. How can I drop and recreate?

Is it best to delete the database from SQL and then just run the Update-Database command again?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T06:22:22+00:00Added an answer on June 18, 2026 at 6:22 am

    I encountered the same error when trying to rename a Key column. To make the migration work, I had to reorder the order of operations in my scaffolded migration script.

    Here, I made sure to order the Drop operations first, then added the new Key field afterwards.

    public partial class RenameKey : DbMigration
    {
        public override void Up()
        {
            DropPrimaryKey("dbo.GameSummary", new[] { "OldId" });
            DropColumn("dbo.GameSummary", "OldId");
            AddColumn("dbo.GameSummary", "Id", c => c.Int(nullable: false, identity: true));
            AddPrimaryKey("dbo.GameSummary", "Id");
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

nobody loved my first question about this: Creating Entity Framework objects with Unity for
I am creating panels in code in this way: DockableContent dockableContent = CreateDockableContent<TView>(model); dockableContent.Show(_dockingManager,
So i have been creating this framework thing that basically puts together source code
I'm trying to implement the repository pattern using entity framework code first rc 1.
I am creating a model binder to use with asp.net mvc. This is what
I used Entity Framework 4.0 for creating my Data Access Layer. Then I found
I have the following code: class Album(models.Model): name = models.CharField(max_length=255, unique=True, null=False) rating =
I am creating a dialog like in this page: http://jqueryui.com/demos/dialog/#modal-confirmation (click view source) on
I am creating this link tag: <link rel=canonical href=<%= request.url %> /> The problem
I had a huge file for creating this GUI and I have shortened it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.