Issues:
Failed executing DbCommand (68ms) [Parameters=[], CommandType=’Text’, CommandTimeout=’30’]
DECLARE @var0 sysname;
SELECT @var0 = [d].[name]
FROM [sys].[default_constraints] [d]
INNER JOIN [sys].[columns] [c] ON [d].[parent_column_id] = [c].[column_id] AND [d].[parent_object_id] = [c].[object_id]
WHERE ([d].[parent_object_id] = OBJECT_ID(N'[tblOrders]’) AND [c].[name] = N’Id’);
IF @var0 IS NOT NULL EXEC(N’ALTER TABLE [tblOrders] DROP CONSTRAINT [‘ + @var0 + ‘];’);
ALTER TABLE [tblOrders] DROP COLUMN [Id];
Microsoft.Data.SqlClient.SqlException (0x80131904): ALTER TABLE DROP COLUMN failed because column ‘Id’ does not exist in table ‘tblOrders’.
ALTER TABLE DROP COLUMN failed because column ‘Id’ does not exist in table ‘tblOrders’.
Solutions:
Generally, these issues coming on code first migration when you are not defining the relations and later modify it and run migration alteration do not happen.
Steps to solve this kind of issue on DB migrations:
- Remove the last table migration in my case it is “tblOrder”.
- Â Aslo remove table model entity creations and entity table navigation property from “ApplicationDbContextModelSnapshot”
- Next delete the table “tblOrder” if you have foriegnkey in it, you will not able to delete may give you error like:
The DELETE statement conflicted with the REFERENCE constraint, so delete all the related table as well. - Â now add db migration by running command in
- package manager console:>Â EntityFrameworkCore\Add-Migration commetnsrelatedtable
- package manager console:> EntityFrameworkCore\Update-Database
It should resolve your problem,
Thanks for visiting this article, if not resolve don’t hesitate to put comments.