The first code migrations are uploaded to the publication settings

Using Windows Azure and trying to publish my MVC3 application. The checkbox "First migration of the execution code" in the settings panel of the Publish web application is inactive. What changes do I need to make to enable it?

+4
source share
2 answers

I believe that when I try to publish an MVC application, the following is disabled: "Performing the first code migration":

enter image description here

This is potentially because either you are not complete code written to migrate the code in your application, and also there is no or incorrect database configuration in your web.config, as described here .

To allow code migration, you must configure the database (in the case of Windows Azure, you need to provide the SQL database information in the web.config file) in web.config, and the full class is written on how the migration code will depend on your model. Here is an example of how to achieve it.

http://msdn.microsoft.com/en-us/library/dd394698#efcfmigrations

+8
source

I assume that you already have an Entity Framework model in your database (if not, then you need to do some reading, the answer from @AvkashChauhan will really be a good starting point).

However, if you have a model and all configurations, for example:

protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Configurations.Add(new YourEntityMap()); } 

and all object mappings, such as:

 public class YourEntityMap : EntityTypeConfiguration<YourEntity> { public YourEntityMap() { this.HasKey(t => t.Id); } } 

and you still do not use the darn flag, you can do the following steps:

Go to Tools > NuGet Package Manager > Package Manager Console

enter image description here

Then in the console write

Enable-Migrations -ContextTypeName Company.Models.YourDevContext

where Company.Models.YourDevContext is your database context (the search for a class that inherits from DbContext should be the same as OnModelCreating override).

after running the command you should get something like:

enter image description here

At this point, you should have the Migrations folder added to the solution more about how to handle migrations here

Hope this saves you some time.

0
source

Source: https://habr.com/ru/post/1435063/


All Articles