This project is read-only.


CreateIfNotExists w/LocalDB does not act the same as EF5


In my EF5 integration tests I can do a Delete Database then do a CreateIfNotExists and the LocalDB would be created and then migrated. In EF6 rc1 the same code gives me:

"Migrations is enabled for context 'Context' but the database does not exist or contains no mapped tables. Use Migrations to create the database and its tables, for example by running the 'Update-Database' command from the Package Manager Console."

file attachments

Closed Sep 3, 2013 at 7:24 PM by ajcvickers
See comments.


ajcvickers wrote Sep 3, 2013 at 5:28 PM

@ShawnC The problem with the way EF5 worked in this regard is that the CreateIfNotExists initializer would not make use of any migrations configuration or any of the scaffolded migrations when creating your database. It would instead just use all the defaults as if you weren't using Migrations at all. This means that the database created in this way could be different from the one created using your Migrations, which could then cause errors, some of them subtle and hard to detect. This is why we prevent this from happening in EF6.

If you want to use an initializer to create your database then looking into the MigrateDatabaseToLatestVersion initializer. This initializer integrates with your Migrations configuration such that it can create the database in the way defined by your migrations.

ShawnC wrote Sep 3, 2013 at 6:46 PM

I can accept this answer and have created a working version based on this information. The only issue I have is if Create and CreateIfNoExists are not going to create the database then it should be marked obsolete or more information given in the intelli-sense.

ajcvickers wrote Sep 3, 2013 at 7:23 PM

@ShawnC These methods work the same as before so long as you don't have Migrations enabled. So if you're just using database initializers and not Migrations, then these methods work just as they did before. It's only when Migrations are enabled for the context that these methods now detect this and prevent the database from being created in a potentially incorrect way.