Merhaba ,
Person tablosunda Country ve City tablolarına ilişki kurmaya çalışıyorum. Country tablosuna ilişki kurduktan sonra City tablosuna ilişki kurmaya çalıştığımızda aşağıdaki hata ile karşılaşmaktayız. City tablosunun Country tablosuyla ilişkisi var.
Konu ile ilgili desteğinizi beklemekteyiz.
Applying migration '20191001081151_Regenerated_Person4988'.
Failed executing DbCommand (11ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
ALTER TABLE [Person] ADD CONSTRAINT [FK_Person_City_CityId] FOREIGN KEY ([CityId]) REFERENCES [City] ([Id]) ON DELETE CASCADE;
System.Data.SqlClient.SqlException (0x80131904): Introducing FOREIGN KEY constraint 'FK_Person_City_CityId' on table 'Person' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints.
Could not create constraint or index. See previous errors.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) at System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async, Int32 timeout, Boolean asyncWrite) at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource
1 completion, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite, String methodName)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.Execute(IRelationalConnection connection, DbCommandMethod executeMethod, IReadOnlyDictionary2 parameterValues) at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.ExecuteNonQuery(IRelationalConnection connection, IReadOnlyDictionary
2 parameterValues)
at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationCommandExecutor.ExecuteNonQuery(IEnumerable`1 migrationCommands, IRelationalConnection connection)
at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.Migrate(String targetMigration)
at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.UpdateDatabase(String targetMigration, String contextType)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
ClientConnectionId:5cf1d597-612d-4a18-b53d-7d8e68e2fc36
Error Number:1785,State:0,Class:16
Introducing FOREIGN KEY constraint 'FK_Person_City_CityId' on table 'Person' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints.
Could not create constraint or index. See previous errors.
2 Answer(s)
-
0
Merhaba,
Oluşturduğunuz 3 entity arasındaki ilişkiyi gözden geçirmeniz gerek. Silme işlemlerinde oluşabilecek sorunlardan dolayı değişikliklikler veritabanına uygulanamıyor.
Oluşturulan migration'lar üzerinde Cascade-Delete'lerde değişiklik yapabilir, veya navigation property'leri nullable yaparak tekrar oluşturabilirsiniz.
Yardımcı olması açısından şu linkteki ilk 2 cevaba göz atmanızı tavsiye ederim: https://stackoverflow.com/questions/17127351/introducing-foreign-key-constraint-may-cause-cycles-or-multiple-cascade-paths
-
0
This issue is closed because it has not had recent activity for a long time.