Open GoogleCodeExporter opened 9 years ago
I have verified that this problem occurs on SQL Server 2005 Developer Edition:
public override void Up()
{
// ...
Database.AddColumn("Person", "user_name", DbType.String, 25,
ColumnProperty.NotNull | ColumnProperty.Indexed | ColumnProperty.Unique);
// ...
}
public override void Down()
{
// ...
Database.RemoveColumn("Person", "user_name");
// ...
}
Result:
System.Data.SqlClient.SqlException: The object 'UQ__Person__0425A276' is
dependent on
column 'user_name'.
ALTER TABLE DROP COLUMN user_name failed because one or more objects access
this column.
Original comment by bow...@gmail.com
on 19 Apr 2010 at 9:50
I remember reading in the source/docs (forgot where) that implicitly creating an
unnamed constraint is a problem because you don't know the name of the
constraint if
you need to delete it in the Down(). Looks like that's what's happening here.
I think you're better off explicitly creating the constraint with
AddUniqueConstraint(), and then explicitly deleting the constraint with
RemoveConstraint() in your Down(). Not only will it give the constraint a more
memorable name, but it will act as an extra check to make sure you're deleting
the
column you intended to - maybe it's just my obsessive nature but I like that.
Original comment by hired.m...@gmail.com
on 23 Apr 2010 at 7:46
Original issue reported on code.google.com by
faede...@gmail.com
on 17 Mar 2010 at 6:25