I had an issue where some of my migrations weren't quite working and I didn't seem to be able to fix it. Therefore I decided to start again. I did the following:
- Deleted the migration history table in the database
- Deleted all the EF tables
- Deleted the migrations folder from my project
- Uninstalled EF5 via NuGet.
I then re-installed EF5 and ran the following;
Enable-Migrations –EnableAutomaticMigrations -Force
This creates my migration.cs file but doesn't touch the database. If I run some code that tries to use the context it complains that the tables don't exist. So I then created a migration:
Add-Migration InitialCreate
The migration this creates however has remembered some state, ignoring the fact it needs to create tables and just lists:
public partial class InitialCreate : DbMigration { public override void Up() { AddColumn("dbo.NetC_EF_ShippingRate", "CurrencyName", c => c.String()); AddColumn("dbo.NetC_EF_ShippingRate", "CreationDate", c => c.DateTime(nullable: false)); } public override void Down() { DropColumn("dbo.NetC_EF_ShippingRate", "CreationDate"); DropColumn("dbo.NetC_EF_ShippingRate", "CurrencyName"); } } How can I get it to forget the state fully and create all tables etc related to the context as if I was starting from scratch?
EDIT I should probably add if I simply try and run this manually created migration I just get errors:
Cannot find the object "dbo.NetC_EF_ShippingRate" because it does not exist or you do not have permissions.
App.config
<?xml version="1.0" encoding="utf-8"?> <configuration> <configSections> <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --></configSections> <entityFramework> <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework"> <parameters> <parameter value="v11.0" /> </parameters> </defaultConnectionFactory> <!--<providers> <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /> </providers>--> </entityFramework> <connectionStrings> <add name="FreightContext" providerName="System.Data.SqlClient" connectionString="Persist Security Info=False;database=DS_Kentico;server=FS-01\DEVSQL2008R2;user id=****;password=****;Current Language=English;Connection Timeout=240;" /> </connectionStrings> <startup> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" /> </startup> </configuration> web.config
<connectionStrings> <clear /> <add name="CMSConnectionString" connectionString="Persist Security Info=False;database=DeltaShelving_Kentico;server=FS-01\DEVSQL2008R2;user id=generic_webuser;password=generic_webuser;Current Language=English;Connection Timeout=240;" /> <add name="FreightContext" providerName="System.Data.SqlClient" connectionString="Persist Security Info=False;database=DS_Kentico;server=FS-01\DEVSQL2008R2;user id=****;password=****;Current Language=English;Connection Timeout=240;" /> </connectionStrings>
Enable-MigrationsorAdd-Migrationactually push anything to the database. The command to do that isUpdate-Database. However, the fact your migrations don't include any create table calls is a bit strange. Do the tables still exist in the database?