Results 1 to 2 of 2
  1. #1

    Thread Starter
    Join Date
    Aug 2016

    how to change department id primary key to identity and do migration to database


    I need to modify class Department to make Department ID identity then make affect by migrations to database sql server 2005 .

    What I Try

    I changed [DatabaseGenerated(DatabaseGeneratedOption.None)] from None to identity .

    then from console write enable-migrations but it give me message

    Migrations have already been enabled in project 'University Data'. To overwrite

    the existing migrations configuration, use the -Force parameter.I also using

    -Force but no any result or changed happened .

    my class Department

    public partial class Department      { 
    public Department()   
    public int DepartmentID { get; set; } 
    public string DepartmentName { get; set; }  
    I have class department inside container Containerclass as following :

    public partial class ContainerClass : DbContext     
    public ContainerClass() : base("name=mycon")      
    public virtual DbSet Departments { get; set; } 
    Table department already created in database.


    i write also in console

    update-database but also nothing changed


    add-migration Department but also nothing changed column DepartmentID not changed to identity


    i add migration then write in up() and down()

    AlterColumn("dbo.Department", "DepartmentID", c => c.Int(nullable: false, identity: true));
    but it not change column to identity

  2. #2

    Re: how to change department id primary key to identity and do migration to database

    Please write did you decide this problem? If yes, write details. Thank you.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts


Click Here to Expand Forum to Full Width