问题
I have a model class named Foo
that has, among others, these properties.
public string StripeRecipientId { get; set; }
public override bool HasProvidedBillingInformation
{
get
{
// return !string.IsNullOrEmpty(this.StripeRecipientId);
return false;
}
}
I have enabled migrations and am using Code First. When I run the update-database
commandlet, whether with -Force
option is specified or not, I get this error:
Column names in each table must be unique.
Column name 'StripeRecipientId' in table
'dbo.Foos' is specified more than once.
I double-checked and triple checked and there's only one column of that name in my model as well as in the table. This column was created already by a previous run of the update-database
commandlet just a while ago.
I am tempted to delete my database and then apply the migrations, but that will mean me having to create a lot of test data just to be able to test the feature I am working on just now.
I am using Entity Framework v6.1.2.
How do I get rid of this error?
回答1:
Run the Add-Migration
command with the -IgnoreChanges
flag. Then run Update-Database
again.
-Update-
These commands should be run in the Package Manager Console. From the main menu: Tools-> NuGet Package Manager -> Package Manager Console.
回答2:
Add-Migration -IgnoreChanges as it is worked for me, but still threw up more errors.
回答3:
If you have also added these properties in the Database tables you will continue to get these errors. So I had to delete the properties from my own table to achieve a re-scaffolding and updated the database subsequently. So run Add-Migration after you must have removed the properties and you will obtain a satisfactory outcome, then run Update-Database it is also expected to be satisfactory.
回答4:
This worked for me.
I run this
Add-Migration -IgnoreChanges
and i got error that your previous two migrations are in pending. Example: Migration-1 , Migration-2I run
update-database -target Migration-1
andupdate-database -target Migration-2
Database Successfully created.
Running Seed method.
来源:https://stackoverflow.com/questions/32845336/column-names-in-each-table-must-be-unique-column-name-striperecipientid-in-ta