0

I have a project that I am working on. While I have been coding it I have created the database on the Local SQL lite on my machine. Now, I need to put it into production and I cannot get the migrations to create anything that is not blank.

Here is my old connection String:

<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=helpdesk;Integrated Security=True" providerName="System.Data.SqlClient" />

I changed it into this:

<add name="DefaultConnection" connectionString="Server=SQL50;Database=HelpDesk;Trusted_Connection=true;" providerName="System.Data.SqlClient" />

I have tried from this thread (Reset Entity-Framework Migrations):

  1. Delete the migrations folder in your project
  2. Delete the __MigrationHistory table in your database (may be under system tables) - However this one doesn't make sense because this is a new database and therefore has no migrations yet.

Whenever I try to create a new migration this is what I get:

public partial class Initial : DbMigration
{
    public override void Up()
    {
    }

    public override void Down()
    {
    }
}

I found this link about Initializers as suggested by Steve Greene Below (http://www.codeguru.com/csharp/article.php/c19999/Understanding-Database-Initializers-in-Entity-Framework-Code-First.htm)

and it suggests using this line of code:

Database.SetInitializer(new DropCreateDatabaseAlways<BlogContext>());

In the main method. However, I do not have a main method or any method similar to that at all.

Community
  • 1
  • 1
djblois
  • 963
  • 1
  • 17
  • 52

1 Answers1

0

Generally this is what I do if I want to start from scratch.

  • Drop the local DB. - you can take a backup etc

  • Delete the migrations folder from my project.(Check in to source control any model changes, this can sometimes cause issues).

  • Run the Enable-Migrations command for my project. (this should add the migrations folder).

  • Run the Add-Migration Initial. (this should the scaffold the db init).

  • Run the Update-Database command (or run your application that uses the DBContext).

DotNetHitMan
  • 931
  • 8
  • 20