locked
Can't migrate Entity Framework RRS feed

  • Question

  • User887623398 posted

    Hi

    I run this command on package manager console :

    pm>add-migration FirstAppDemo

    but keeping <g class="gr_ gr_100 gr-alert gr_gramm gr_inline_cards gr_run_anim Grammar multiReplace" id="100" data-gr-id="100">get</g> this image:

    The project first app demo failed to build.

    What should I do?

    please inform.

    regards

    Saeed

    Wednesday, July 25, 2018 4:57 PM

All replies

  • User-369506445 posted

    Hi

    It means that there have something wrong in your project, you need to check your project, rebuild it.

    If we want to Enabling Migrations .The first step is to enable migrations for our context..

    • Run the Enable-Migrations command in Package Manager Console . (make sure that default project is the project where your context class is).

    Code First Migrations has two primary commands that you are going to become familiar with.

    • Add-Migration will scaffold the next migration based on changes you have made to your model since the last migration was created
    • Update-Database will apply any pending migrations to the database

    Please refer to the links below for more details:

    http://www.entityframeworktutorial.net/code-first/automated-migration-in-code-first.aspx 

    http://msdn.microsoft.com/en-us/data/jj591621 

    http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/migrations-and-deployment-with-the-entity-framework-in-an-asp-net-mvc-application

    Wednesday, July 25, 2018 5:27 PM
  • User887623398 posted

    Thanks for your reply.

    I'm afraid my entity framework and sql configuration is correct in start up.cs.

    Here comes my configuration:

            public void ConfigureServices(IServiceCollection services)
            {
                services.AddMvc();
                
                var sqlconnection = "Data Source=(localdb)\\mssqllocaldb;Initial Catalog=FirstAppDemo";
                services.AddDbContext<FirstAppDemoDbContext>(dbcontextoption => dbcontextoption.UseSqlServer(sqlconnection));
    
    
    
            }

    Would you please let me know if any thing is wrong?

    Wednesday, July 25, 2018 6:31 PM
  • User-369506445 posted

    It's not depended to your config

    According to your error, I said first build your project and sure you do not get any error

    If your project become build success

    Then 

    • Run the Enable-Migrations command in Package Manager Console . (make sure that default project is the project where your context class is)

    Next Add-Migration will scaffold the next migration based on changes you have made to your model since the last migration was created

    Wednesday, July 25, 2018 6:39 PM
  • User-369506445 posted

    Please refer to below link

    https://docs.microsoft.com/en-us/ef/core/get-started/aspnetcore/new-db

    Wednesday, July 25, 2018 6:45 PM
  • User887623398 posted

    I built my project and there is no error.

    In <g class="gr_ gr_20 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" id="20" data-gr-id="20">microsoft</g> documentation comes to this command:

    Add-Migration InitialCreate

    and when I write and run this command after a while this error comes which is highlighted:

    Object reference not set to an instance of an object.

    please inform.
     

    Wednesday, July 25, 2018 7:35 PM
  • Wednesday, July 25, 2018 7:45 PM
  • User1520731567 posted

    Hi SaeedP,

    I can't reproduce your issue,

    It looks like this might have been introduced by some of the changes made around connection managemenrt,you could refer to these links,

    hope them could be helpful to you:

    https://github.com/aspnet/EntityFramework6/issues/504

    https://github.com/aspnet/EntityFramework6/issues/398

    Best Regards.

    Yuki Tao

    Thursday, July 26, 2018 10:06 AM
  • User1528429020 posted

    Having the same problem, if you found any solution please help

    PM> add-migration AddBooleanPurposeColumnsToCustomersTable
    The project 'CustomersDemo' failed to build.

    Tuesday, June 15, 2021 3:24 PM