locked
EF 4.3.1 doesn't generate InitialCreate file RRS feed

  • Question

  • I'm trying to practice with EF 4.3.1.I done at all but when i want to change my model structure. I run command  "Enable-Migrations"

    it noticed that:

    No classes deriving from DbContext found in the current project.
    Edit the generated Configuration class to specify the context to enable migrations for.
    Migrations have already been enabled in project '****'. To overwrite the existing migrations configuration, use the -Force parameter.

    I've tried many ways but still not solve the problem.

    As i read on our website. when i run command "Enable-Migrations" i will generate 2 files. Configuration and initial. But in my case.it just generates configuration file.

    Saturday, November 10, 2012 4:43 PM

Answers

  • Hi

    There are three main scenarios that I know of that cause this behavior:

    1. Your database was created with a version of EF before 4.3

    2. Your database was not created by code fist

    3. You don't have a database yet

    I assume you've hit either 1 or 2.

    This is actually a rough edge on migrations that I would like to fix at some point. An issue discussing it is here: http://entityframework.codeplex.com/workitem/350

    You can upvote it if you like, that will make it get into the backlog sooner.

    In order to resolve the issue for you then you can do the following:

    1. scaffold a migration with add-migration. This will create a new migration to represent the state of your database

    2. call update-database with the script flag to generate the sql for the migration

    3. remove all the sql from the script except the part that adds rows to the migrations history table

    4. Run the sql

    After you have done this then you have an initial migration and you database knows that it doesn't need to be run. So you can continue with migrations as normal. Other devs can also then use the migration to create an initial database if it is required.

    Alternatively you could re-create your database with the initial create migration. It would be faster, but would result in data loss.


    We are seeing a lot of great Entity Framework questions (and answers) from the community on Stack Overflow. As a result, our team is going to spend more time reading and answering questions posted on Stack Overflow. We would encourage you to post questions on Stack Overflow using the entity-framework tag. We will also continue to monitor the Entity Framework forum.

    Friday, November 16, 2012 11:51 PM

All replies

  • Hi Tuanhoang123,

    Welcome to the MSDN forum.

    First, could you please let me know whether you are using code first approach?

    Second, does your context class derive from DbContext? If your context class derives from ObjectContext, please change it to DbContext.

    Third, please check if you set the correct project on package manager console: http://stackoverflow.com/questions/9527366/cannot-enable-migrations-for-ef-4-3-in-class-library

    Best Regards,


    Alexander Sun [MSFT]
    MSDN Community Support | Feedback to us

    Tuesday, November 13, 2012 2:24 AM
  • Hi

    There are three main scenarios that I know of that cause this behavior:

    1. Your database was created with a version of EF before 4.3

    2. Your database was not created by code fist

    3. You don't have a database yet

    I assume you've hit either 1 or 2.

    This is actually a rough edge on migrations that I would like to fix at some point. An issue discussing it is here: http://entityframework.codeplex.com/workitem/350

    You can upvote it if you like, that will make it get into the backlog sooner.

    In order to resolve the issue for you then you can do the following:

    1. scaffold a migration with add-migration. This will create a new migration to represent the state of your database

    2. call update-database with the script flag to generate the sql for the migration

    3. remove all the sql from the script except the part that adds rows to the migrations history table

    4. Run the sql

    After you have done this then you have an initial migration and you database knows that it doesn't need to be run. So you can continue with migrations as normal. Other devs can also then use the migration to create an initial database if it is required.

    Alternatively you could re-create your database with the initial create migration. It would be faster, but would result in data loss.


    We are seeing a lot of great Entity Framework questions (and answers) from the community on Stack Overflow. As a result, our team is going to spend more time reading and answering questions posted on Stack Overflow. We would encourage you to post questions on Stack Overflow using the entity-framework tag. We will also continue to monitor the Entity Framework forum.

    Friday, November 16, 2012 11:51 PM