Database Tables are not created for ApiDbContext
Opened this issue · 0 comments
Running the Migration command for ApiDbContext
dotnet ef migrations add {Name} --project .\src\Api\ --startup-project .\src\Api\Api.csproj --msbuildprojectextensionspath ..build\obj\Api\ --context ApiDbContext --output-dir
Data\Migration\ApiDb``
Does not create's table in database, though the first command worked after updating database for ApplicationDbContext but in this case updating database shows error. that error
Failed executing DbCommand (64ms) [Parameters=[], CommandType='Text', CommandTimeout='30'] CREATE TABLE [MainContraAccount] ( [Id] int NOT NULL IDENTITY, [MainAccountId] int NOT NULL, [RelatedContraAccountId] int NOT NULL, CONSTRAINT [PK_MainContraAccount] PRIMARY KEY ([Id]), CONSTRAINT [FK_MainContraAccount_Account_MainAccountId] FOREIGN KEY ([MainAccountId]) REFERENCES [Account] ([Id]) ON DELETE CASCADE, CONSTRAINT [FK_MainContraAccount_Account_RelatedContraAccountId] FOREIGN KEY ([RelatedContraAccountId]) REFERENCES [Account] ([Id]) ON DELETE CASCADE );info: Microsoft.EntityFrameworkCore.Database.Command[20101] Executed DbCommand (7ms) [Parameters=[], CommandType='Text', CommandTimeout='30'] CREATE TABLE [ItemCategory] ( [Id] int NOT NULL IDENTITY, [ItemType] int NOT NULL, [MeasurementId] int NULL, [SalesAccountId] int NULL, [InventoryAccountId] int NULL, [CostOfGoodsSoldAccountId] int NULL, [AdjustmentAccountId] int NULL, [AssemblyAccountId] int NULL, [Name] nvarchar(max) NULL, CONSTRAINT [PK_ItemCategory] PRIMARY KEY ([Id]), CONSTRAINT [FK_ItemCategory_Account_AdjustmentAccountId] FOREIGN KEY ([AdjustmentAccountId]) REFERENCES [Account] ([Id]) ON DELETE NO ACTION, CONSTRAINT [FK_ItemCategory_Account_AssemblyAccountId] FOREIGN KEY ([AssemblyAccountId]) REFERENCES [Account] ([Id]) ON DELETE NO ACTION, CONSTRAINT [FK_ItemCategory_Account_CostOfGoodsSoldAccountId] FOREIGN KEY ([CostOfGoodsSoldAccountId]) REFERENCES [Account] ([Id]) ON DELETE NO ACTION, CONSTRAINT [FK_ItemCategory_Account_InventoryAccountId] FOREIGN KEY ([InventoryAccountId]) REFERENCES [Account] ([Id]) ON DELETE NO ACTION, CONSTRAINT [FK_ItemCategory_Measurement_MeasurementId] FOREIGN KEY ([MeasurementId]) REFERENCES [Measurement] ([Id]) ON DELETE NO ACTION, CONSTRAINT [FK_ItemCategory_Account_SalesAccountId] FOREIGN KEY ([SalesAccountId]) REFERENCES [Account] ([Id]) ON DELETE NO ACTION ); fail: Microsoft.EntityFrameworkCore.Database.Command[20102] Failed executing DbCommand (64ms) [Parameters=[], CommandType='Text', CommandTimeout='30'] CREATE TABLE [MainContraAccount] ( [Id] int NOT NULL IDENTITY, [MainAccountId] int NOT NULL, [RelatedContraAccountId] int NOT NULL, CONSTRAINT [PK_MainContraAccount] PRIMARY KEY ([Id]), CONSTRAINT [FK_MainContraAccount_Account_MainAccountId] FOREIGN KEY ([MainAccountId]) REFERENCES [Account] ([Id]) ON DELETE CASCADE, CONSTRAINT [FK_MainContraAccount_Account_RelatedContraAccountId] FOREIGN KEY ([RelatedContraAccountId]) REFERENCES [Account] ([Id]) ON DELETE CASCADE ); System.Data.SqlClient.SqlException (0x80131904): Introducing FOREIGN KEY constraint 'FK_MainContraAccount_Account_RelatedContraAccountId' on table 'MainContraAccount' 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, Action
1 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(TaskCompletionSource1 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, IReadOnlyDictionary
2 parameterValues)
ClientConnectionId:f4141637-11a8-4861-87dc-8387632f34d1
Error Number:1785,State:0,Class:16
System.Data.SqlClient.SqlException (0x80131904): Introducing FOREIGN KEY constraint 'FK_MainContraAccount_Account_RelatedContraAccountId' on table 'MainContraAccount' 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(IEnumerable1 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:f4141637-11a8-4861-87dc-8387632f34d1 Error Number:1785,State:0,Class:16 Introducing FOREIGN KEY constraint 'FK_MainContraAccount_Account_RelatedContraAccountId' on table 'MainContraAccount' 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.