سلام و تشکر از دورهی خوبتون.
وقتی که Migration رو درست میکنم و میخوام دیتابیس رو آپدیت کنم، این ارور داده میشه:
PM> Update-Database
Build started...
Build succeeded.
Microsoft.EntityFrameworkCore.Infrastructure[10403]
Entity Framework Core 6.0.3 initialized 'SurveyfaContext' using provider 'Microsoft.EntityFrameworkCore.SqlServer:6.0.3' with options: None
Microsoft.EntityFrameworkCore.Database.Command[20101]
Executed DbCommand (35ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT 1
Microsoft.EntityFrameworkCore.Database.Command[20101]
Executed DbCommand (30ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT OBJECT_ID(N'[__EFMigrationsHistory]');
Microsoft.EntityFrameworkCore.Database.Command[20101]
Executed DbCommand (2ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT 1
Microsoft.EntityFrameworkCore.Database.Command[20101]
Executed DbCommand (5ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT OBJECT_ID(N'[__EFMigrationsHistory]');
Microsoft.EntityFrameworkCore.Database.Command[20101]
Executed DbCommand (4ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT [MigrationId], [ProductVersion]
FROM [__EFMigrationsHistory]
ORDER BY [MigrationId];
Microsoft.EntityFrameworkCore.Migrations[20402]
Applying migration '20220322093147_Init'.
Applying migration '20220322093147_Init'.
Microsoft.EntityFrameworkCore.Database.Command[20101]
Executed DbCommand (14ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
CREATE TABLE [Items] (
[Id] int NOT NULL IDENTITY,
[Name] nvarchar(max) NOT NULL,
[Discriminator] nvarchar(max) NOT NULL,
CONSTRAINT [PK_Items] PRIMARY KEY ([Id])
);
Microsoft.EntityFrameworkCore.Database.Command[20101]
Executed DbCommand (2ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
CREATE TABLE [Students] (
[Id] int NOT NULL IDENTITY,
[NationalCode] int NOT NULL,
[UserName] nvarchar(max) NOT NULL,
CONSTRAINT [PK_Students] PRIMARY KEY ([Id])
);
fail: Microsoft.EntityFrameworkCore.Database.Command[20102]
Error Here => Failed executing DbCommand (11ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
CREATE TABLE [ChoiceToSurveys] (
[Id] int NOT NULL IDENTITY,
[ChoiceId] int NOT NULL,
[SurveyId] int NOT NULL,
CONSTRAINT [PK_ChoiceToSurveys] PRIMARY KEY ([Id]),
CONSTRAINT [FK_ChoiceToSurveys_Items_ChoiceId] FOREIGN KEY ([ChoiceId]) REFERENCES [Items] ([Id]) ON DELETE CASCADE,
CONSTRAINT [FK_ChoiceToSurveys_Items_SurveyId] FOREIGN KEY ([SurveyId]) REFERENCES [Items] ([Id]) ON DELETE CASCADE
);
Failed executing DbCommand (11ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
CREATE TABLE [ChoiceToSurveys] (
[Id] int NOT NULL IDENTITY,
[ChoiceId] int NOT NULL,
[SurveyId] int NOT NULL,
CONSTRAINT [PK_ChoiceToSurveys] PRIMARY KEY ([Id]),
CONSTRAINT [FK_ChoiceToSurveys_Items_ChoiceId] FOREIGN KEY ([ChoiceId]) REFERENCES [Items] ([Id]) ON DELETE CASCADE,
CONSTRAINT [FK_ChoiceToSurveys_Items_SurveyId] FOREIGN KEY ([SurveyId]) REFERENCES [Items] ([Id]) ON DELETE CASCADE
);
Microsoft.Data.SqlClient.SqlException (0x80131904): Introducing FOREIGN KEY constraint 'FK_ChoiceToSurveys_Items_SurveyId' on table 'ChoiceToSurveys' 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 Microsoft.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at Microsoft.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at Microsoft.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at Microsoft.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at Microsoft.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean isAsync, Int32 timeout, Boolean asyncWrite)
at Microsoft.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, Boolean sendToPipe, Int32 timeout, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry, String methodName)
at Microsoft.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteNonQuery(RelationalCommandParameterObject parameterObject)
at Microsoft.EntityFrameworkCore.Migrations.MigrationCommand.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 connectionString, String contextType)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabaseImpl(String targetMigration, String connectionString, String contextType)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabase.<>c__DisplayClass0_0.<.ctor>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
ClientConnectionId:85be481c-e541-405b-9329-4f2aa57ff280
Error Number:1785,State:0,Class:16
Error is here => Introducing FOREIGN KEY constraint 'FK_ChoiceToSurveys_Items_SurveyId' on table 'ChoiceToSurveys' 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.
با تشکر از پاسخگوییتون