EF Code First from Database - Already an object in the database

c# entity-framework entity-framework-6


I introduced ADO.NET EF 6 to a brand-new.NET project.
I used the EF wizard and selected Code First from the Database.
I then decided on a table. Call it "Product" for now.
"Public partial class Product" and "Public partial class Model1" were so established.

To query the "Product," I instantly prepared a LINQ query in my application, but I receive the following error.

There is already an object named 'Product' in the database.

The following is what I see when I run SQL Profile:

CREATE TABLE [dbo].[Product] ...

Since the table already exists, I don't understand why the project is trying to build it.

I've read a few articles that said I must enable migrations, but I really don't want my project to be able to make new database tables.
(We have a DBA that refuses to grant us permission to "easily" build tables in the database.)

Then, I made the decision to try building a "internal sealed class Configuration" and a "Migrations" subdirectory using the following:

public Configuration()
    AutomaticMigrationsEnabled = false;
    AutomaticMigrationDataLossAllowed = false;

Now I have a new error.

Unable to update database to match the current model because there are pending changes and automatic migration is disabled. Either write the pending model changes to a code-based migration or enable automatic migration. Set DbMigrationsConfiguration.AutomaticMigrationsEnabled to true to enable automatic migration.

How do I correct this?

So I wrote the exact same code and pointed it at the same database in both a VB.NET and a C# application.
The "already in database" problem exists with the C# version.
The "already in database" problem is not present in the VB.NET version.

11/12/2015 2:21:55 PM

Accepted Answer

5/23/2017 12:06:43 PM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow