ALTER TABLE DROP COLUMN失败,因为一个或多个对象访问此列 [英] ALTER TABLE DROP COLUMN failed because one or more objects access this column
问题描述
我正在尝试这样做:
ALTER TABLE CompanyTransactions DROP COLUMN Created
但是我明白了:
Msg 5074,Level 16,状态1,行2
对象'DF__CompanyTr__Creat__0CDAE408'取决于列'Created'。
消息4922,级别16,状态9,第2行
更改表拖放列创建失败,因为一个或多个对象访问此列。
Msg 5074, Level 16, State 1, Line 2 The object 'DF__CompanyTr__Creat__0CDAE408' is dependent on column 'Created'. Msg 4922, Level 16, State 9, Line 2 ALTER TABLE DROP COLUMN Created failed because one or more objects access this column.
这是代码优先表。不知何故,迁移变得一团糟,我试图手动回退一些更改。
This is a code first table. Somehow the migrations have become all messed up and I am trying to manually roll back some changed.
我不不知道这是什么:
DF__CompanyTr__Creat__0CDAE408
推荐答案
在删除列之前,必须从列中删除约束
。您引用的名称是默认约束
。
You must remove the constraints
from the column before removing the column. The name you are referencing is a default constraint
.
例如
alter table CompanyTransactions drop constraint [df__CompanyTr__Creat__0cdae408];
alter table CompanyTransactions drop column [Created];
这篇关于ALTER TABLE DROP COLUMN失败,因为一个或多个对象访问此列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!