core mvc code first approach migration issues & fixes| failed executing DbCommand| LTER TABLE DROP COLUMN failed | Cannot find the object “tablename” because it does not exist

Table of Contents


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 + ‘];’);

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’.



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:

  1. Remove the last table migration in my case it is “tblOrder”.
  2.  Aslo remove table model entity creations and entity table navigation property from “ApplicationDbContextModelSnapshot”
  3. 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.
  4.  now add db migration by running command in
  5. package manager console:>  EntityFrameworkCore\Add-Migration commetnsrelatedtable
  6. 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.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top