Domanda

I want to drop some tables and create again following my models design. But the CodeFirst never do it, keeping trying to apply the changes that I did, but for some reason he can't. The Designs of models class is ok but the tables on SQL is not and thats why and want to drop and recreate again.

I did some changes on model and especially with keys and Foreign Keys. So why I think if I could set which tables I would like to drop, code first will Understand my new implementation.

Erro output update-database

PM> update-database -verbose -force
Using StartUp project 'WebTier'.
Using NuGet project 'Target.Data.SqlServer'.
Specify the '-Verbose' flag to view the SQL statements being applied to the target database.
System.InvalidOperationException: Unable to determine the principal end of an association between the types 'Target.Data.Model.TacticalGoal' and 'Target.Data.Model.ICB'. The principal end of this association must be explicitly configured using either the relationship fluent API or data annotations.
   at System.Data.Entity.ModelConfiguration.Edm.Services.AssociationTypeMappingGenerator.GenerateIndependentAssociationType(EdmAssociationType associationType, DbDatabaseMapping databaseMapping)
   at System.Data.Entity.ModelConfiguration.Edm.Services.AssociationTypeMappingGenerator.Generate(EdmAssociationType associationType, DbDatabaseMapping databaseMapping)
   at System.Data.Entity.ModelConfiguration.Edm.Services.DatabaseMappingGenerator.GenerateAssociationTypes(EdmModel model, DbDatabaseMapping databaseMapping)
   at System.Data.Entity.ModelConfiguration.Edm.Services.DatabaseMappingGenerator.Generate(EdmModel model)
   at System.Data.Entity.DbModelBuilder.Build(DbProviderManifest providerManifest, DbProviderInfo providerInfo)
   at System.Data.Entity.DbModelBuilder.Build(DbConnection providerConnection)
   at System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext)
   at System.Data.Entity.Internal.RetryLazy`2.GetValue(TInput input)
   at System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
   at System.Data.Entity.Internal.LazyInternalContext.get_CodeFirstModel()
   at System.Data.Entity.Infrastructure.EdmxWriter.WriteEdmx(DbContext context, XmlWriter writer)
   at System.Data.Entity.Migrations.Extensions.DbContextExtensions.<>c__DisplayClass1.<GetModel>b__0(XmlWriter w)
   at System.Data.Entity.Migrations.Extensions.DbContextExtensions.GetModel(Action`1 writeXml)
   at System.Data.Entity.Migrations.Extensions.DbContextExtensions.GetModel(DbContext context)
   at System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration configuration, DbContext usersContext)
   at System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration configuration)
   at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.GetMigrator()
   at System.Data.Entity.Migrations.Design.ToolingFacade.UpdateRunner.RunCore()
   at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.Run()
Unable to determine the principal end of an association between the types 'Target.Data.Model.TacticalGoal' and 'Target.Data.Model.ICB'. The principal end of this association must be explicitly configured using either the relationship fluent API or data annotations.
È stato utile?

Soluzione

You can try to downgrade your migrations. Going back to your past migrations which were created before your "create table" migrations, will solve your problem. You can write this command in Package-Manager Console:

Update-Database –TargetMigration: yourPreviousMigrationName

After that you can create again your tables with new forms.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top