0

Hi i need help with something because the migrations and generally the logic is driving me crazy .. I made an extendable Web application using the answer in this link "MEF with MVC 4 or 5 - Pluggable Architecture (2014)" . And of course as every Web Application must create models in order to work . When i try to run the update-database in the migrations instead of ignoring every model idint create in the module it just tries to recreate and of course it throws errors . How ican make it so if it finds a table that exists and isnt changed to ignore it so to show no error messages , just to go to next models.

The mdoels are :

>  [Table("ProjectRleases")]
    public class FileReleases
    {
        [Required]
        public int Id { get; set; }
        public string Tittle { get; set; }
         [Required]
        public string Version { get; set; }
        public DateTime Published { get; set; }
        [DataType(DataType.Html)]
        public string content { get; set; }
        [DataType(DataType.Upload)]
        public virtual List<ProjectFiles> Files { get; set; }
        [Required]
        public virtual Project Project { get; set; }
        [Required]
        public virtual ApplicationUser UploadedBy { get; set; }
      //
        [Required]
        public virtual ChangeLog ChangeLog { get; set; }
    }



[Table(" Projects")]
    public class Project
    {
        [Required]
        public int Id { get; set; }
        //   public int revision { get; set; }
        [Required]
        [DataType(DataType.Text)]
        public string Name { get; set; }
        [DataType(DataType.MultilineText)]
        public string Description { get; set; }
        [Required]
        public virtual ApplicationUser Admininstrator { get; set; }
        public virtual List<ApplicationUser> Members { get; set; }
        public virtual List<ProjectNews> News { get; set; }
        public virtual List<FileReleases> Releases { get; set; }
        public virtual List<ChangeLog> ChangeLogs { get; set; }


    }
  [Table("ProjectNews")]
    public class ProjectNews:News
    {
        [Required]
        public virtual Project Project{ get; set; }
         [Required]
        public int ProjectId { get; set; }
    }
Community
  • 1
  • 1

2 Answers2

0

You need to make an initial 'Baseline' migration (add-migration 'Baseline'). This will have Up() and Down() methods with your existing tables. You can remove the redundant code and then perform update-database. Now you can modify your models in code first fashion and the next migration will only pickup those changes. See http://www.ralphlavelle.net/2012/02/using-entity-framework-code-first-with_26.html

Steve Greene
  • 12,029
  • 1
  • 33
  • 54
0

I have two projects which both of them have migrations configuration of course, the one which is working is a class library project one ... The thing you are talking about is about the one that works or the other one?

Also I think I tried that one and the up and down methods had 0 code on them